Pathfinding is the correct term.
It's not terribly complicated to do, but it is moderately complex. You should be able to achieve it as either a plugin or a common event, but it would be much less efficient as a common event because you'd have to have it running in parallel and checking things every time you press a button to move. (and as best as I can think, you'd have to be throwing in script calls anyway)
So it would be more efficient to add as a plugin, because you can have the code kick in after it's already determined that the tile you want to move into is impassable.
You then have it see if there is a tile on one side of that which is passable, and if so you override the input and make the player move toward it instead of the direction they pressed.
Thanks. I was kind of hoping to discover some existing plugin for MZ, but it still seems as if a lot of MZ plugin development is in its infancy, in comparison to previous iterations of Maker.
I don't know about infancy, a lot of pretty complex stuff has been put out there. But yes, there are fewer plugins for MZ than MV, which makes sense as it's been out for fewer years.
To be fair to MZ, I never saw a plugin like this for MV, either.
But here it is - works for both MV and MZ in my testing. It pops a warning in the MZ plugin manager, but it appears to be perfectly compatible - I just can't bother to figure out how to get rid of that 😉
Enjoy!