MV Smarter pathfinding plugin?

Has anyone made a plugin that improves the pathfinding used when clicking on the map?

The only plugin I can find on the forums that does anything with pathfinding is Shaz's Smart Pathfinding plugin; but, as far as I can tell, all it does is makes events use the same pathfinding as touch movement. It doesn't alter how touch movement behaves in any way.

The following is a list of things I'd like to change about the pathfinding. It's just the things I've thought of and is probably not comprehensive. (Feel free to suggest other things if you think of them.)

  • Better pathing around obstacles. Currently, if you click on the other side of a wall, the player walks up to the wall and stops – even if there's a viable path around it.
  • Avoidance of damage terrain.
  • Prefer moving horizontally in sloped regions (eg when using Cae_SlopeMove).
  • Avoidance of events, or at least some types of events – map transfers in particular. Possibly others, I'd have to think on it more.
  • Contrarily, understanding of "teleporters" – events that transfer you to another point on the same map.

I'm thinking of creating such a plugin myself if it doesn't already exist, but I thought I may as well search and ask around first, just in case it has already been done.
Unfortunately pathfinding options in RPG Maker are severely lacking. They're pretty much all based on A* and I can't think of any that avoid events.

Your best options are Muki's plugin or the paid Rosedale collision plugin.

Better pathfinding is one of the reasons I picked up another engine (which has navmeshes, boids, the ability to mark any object as a pathfinding obstacle, etc).
They're pretty much all based on A*
You say that like you think it's a problem…?

Do you know where I can find Muki's plugin? I think I should at least see what it's liked even if I still decide to make my own…
Edit: companion plugin
Hmm, I see.

It looks like half of that plugin is along the lines of Galv's Move Route Extras (though only slightly overlapping – that is, they both provide more move route options but mostly not the same ones), but then it also overrides findDirectionTo, which is the key to the touch movement, and it also has an option to use that pathfinding for event movement like Shaz's Smart Pathfinding does.

Seeing that actually makes me wonder if the bad pathing around obstacles is a direct result of the search limit. Perhaps just increasing the search limit would let it properly get to the other side of a wall when there's a path.

That doesn't help with the other requirements though… and μ'ki's plugin indeed doesn't do anything to modify the guts of the A* (cost function and neighbours).

Unless someone else comes up with another option, it looks like I'll probably have to roll my own after all.

Also, as an aside: I just thought of another thing that would be nice to have in a pathfinding plugin: the ability to path through "teleporters" – that is, map transfer commands that don't transfer you to another point on the same map.
They're pretty much all based on A* ...
As with @SolarFlare , I'm also missing why this is a problem. What algorithm would you suggest instead?

Avoidance of damage terrain.
This probably is just a matter of processing damage tiles as impassable?
As with @SolarFlare , I'm also missing why this is a problem. What algorithm would you suggest instead?
Depends on the use case, but algorithms like boids and flowfields are better when there are multiple things pathfinding at once, e.g. mobs and rts behavior.
I'm not sure what those are (I found boids on Wikipedia, but not as a pathfinding algorithm per se, more as swarm simulation), but I think A* should be good enough for my purposes, at least.

The existing findDirectionTo function is actually A* already. Unfortunately it's not very customizable, so I would have to replace the entire function just to slot in any kind of custom neighbour determination (which is required by pretty much all of the points noted in my first point, I think – except the first, which is likely just increasing the search limit).
Spoiler: about A*
A* uses a heuristic to score any given node. The idea is to move from one node to the next until obtaining the best score, e.g. 0 (if using a "distance to goal" heuristic). Then you have a path!

A* is not the most efficient algorithm, but it is guaranteed to find a path if:
  1. The heuristic is "perfect", e.g. it accurately predicts the distance to the goal.
    • This condition is met by default, but may break if using certain plugins.
  2. And all available tiles are checked before giving up.
    • By default it searches only up to 12 tiles away.
The default search limit is aimed to work accurately and efficiently with the default screen size: 17x13 tiles. If you're using a larger screen size, or your maps are particularly complex, then failure can be expected.

In case it helps, here's an interactive demo to help visualise how A* works:
To emulate RPG Maker's default pathfinding, choose Heuristic: Manhattan and uncheck all Options. For further technical details, I generally recommend this site.

Like you've said, I think that realistically you'd need 1 big plugin for all the pathfinding stuff, since the core findDirectionTo is almost entirely just one big black box: it outsources the search limit, but basically nothing else. 😴

Everything you've mentioned seems feasible~
Spoiler: thoughts
Better pathing around obstacles. Currently, if you click on the other side of a wall, the player walks up to the wall and stops – even if there's a viable path around it.
This might just be a matter of increasing the node search limit, e.g.
JavaScript:
/*:
 * @target MV MZ
 * @plugindesc Make pathfinding check further away before giving up.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/threads/179951/
 * @help Free to use and/or modify for any project, no credit required.
 */
// Override - check up to 18 tiles away (default 12).
Game_CharacterBase.prototype.searchLimit = function() { return 18; };
Note that this would make all pathfinding potentially check 50% further away. Depending on map layout, this quadratically increases the number of tiles available for checking: it will be particularly noticeable on open-plan maps, much less so in narrow corridors.

Also, note that the search limit need not be sufficient to reach the goal, except in the most contrived situations. Typically it just needs to be enough to get you (heuristically) nearer to the goal.

Avoidance of damage terrain.
"Avoidance" typically involves applying movement costs, e.g. make travelling over certain tiles, such as damage floors or specific regions, contribute more than 1 point of "distance travelled" to the heuristic, making it a less optimal path.

Prefer moving horizontally in sloped regions (eg when using Cae_SlopeMove).
This could be done by changing the order of directional checks (e.g. <- -> ↑ ↓ instead of ↓ <- -> ↑) or with movement costs. Specific plugins/mechanics will likely need their own specific approaches.

Avoidance of events, or at least some types of events – map transfers in particular. Possibly others, I'd have to think on it more.
Movement costs again, e.g. via event notetag.

Contrarily, understanding of "teleporters" – events that transfer you to another point on the same map.
The pathfinding algorithm would have to have to be changed so it generates neighbouring tiles appropriately when situated appropriately relative to a "transfer" event. Feasible, but more complex if you want to accommodate other features like a moving entry/exit, randomised exit, etc.
The biggest problems with pathfinding in RPG Maker is massive lag, especially with multiple events pathfinding, getting stuck on walls all the time, and poor response to dynamic maps with moving events.
The pathfinding options all seem to go by the 48x48 tile grid for node calculations too. My research says some of these issues are inherent to A*.

I personally got tired of dealing with it in RPG Maker when other engines have multiple pathfinding options that let you adjust node granularity, give you far more control over the size and shape of collision masks of objects with WYSIWYG editors built directly into the engine, and simply work better straight out of the box.
I'm not sure how you'd get massive lag if it's only used by touch movement… I could maybe see that happening if every moving event on the map was calling A* on every frame.

Which issues do you think are inherent to A*? Getting stuck on walls shouldn't be an issue of A*. I think A* probably isn't good at dealing with moving obstacles though.

I don't think collision masks have much to do with pathfinding at all…
I'm not sure how you'd get massive lag if it's only used by touch movement
By default it's only used by touch movement but if you use Shaz, Muki, or other plugins to have events pathfind it lags. I am not the only one to experience this, especially when plugins like KOTC's pathfinder promise to reduce lag as a selling point (his one is buggy and crashes).

Lag, poor response to moving obstscles, and getting stuck (this is a function of not enough search length, but extending the length also increases lag) were cited as issues with A* in my research.

Custom collision masks are just another nice bonus feature other engines have that RPG Maker doesn't, when you have say, large enemies that take up more than 48x48 area that you want to pathfind or an unusual shape like a long car, in an environment made up of more than rigid 48x48 tile and event blocks.
If you have a twenty or thirty or a hundred events all pathfinding on every frame, I could maybe see it lagging. My use-case is primarily for touch movement though – I think there are few if any events that I'd want to use pathfinding for.

With moving obstacles, I think in many cases it's good enough to just ignore them – that is, treat their location as passable. They're going to move anyway, so by the time you actually get there, chances are they'll be gone. And if not, then there's a pretty good chance they'll move out of the way right after you get there.

And it seems you meant custom collision masks for the agent of pathfinding? I think that could actually be done in A* even on a square grid, as A* at its core is an algorithm on graphs, not a square grid, but it would be tricky.
If you have a twenty or thirty or a hundred events all pathfinding on every frame, I could maybe see it lagging
No it will lag even with only one event pathfinding if the search length is long enough. The issue compounds exponentially with every pathfinding event. It's noticable with only two or three.

I think you are narrowly focused on only your own use case of using pathfinding for only the player (one agent) when clicking to a location.

I am thinking bigger, with extremes like RTS gameplay where armies of units are pathfinding simultaneously.

Custom collision masks matter with the pathfinding agents, obstacles (e.g. other moving events) and environment, unless everything is comprised strictly of 48x48 blocks.
I have used A* pathfinding in another project with several agents at a time, and I don't recall any lag (though I think there was lag when I had added twenty or thirty agents as a test). Though, that project isn't even in JavaScript, so perhaps it's just more optimized at a low level…

Incidentally, A* is perfectly fine for armies in a turn-based strategy game… but I guess that's because it's turn-based, so they're not all pathfinding simultaneously.

But in any case: yes, I'm somewhat narrowly focused on my own use-case of better pathfinding for touch movement. Though my game does have a few events that approach the player, I don't think any of them require better pathfinding than the game already does (which is, if I'm not mistaken, not even A* by default); and even if they were to use A*, I bet they could work well enough at an even lower search limit than the player uses.
Incidentally, A* is perfectly fine for armies in a turn-based strategy game… but I guess that's because it's turn-based, so they're not all pathfinding simultaneously.
It's fine for SRPGs because only one unit is pathfinding at a time and the unit movement range is usually limited to a certain number of tiles, keeping computational load low. It's why I specified RTS. The real time component matters.

Another issue that I just discovered the term for is A*'s inability to do "any angle" pathfinding, which is considered more fluid and natural than moving strictly along gridlines. This is what I am interested in for my games.
A*'s inability to do "any angle" pathfinding, which is considered more fluid and natural than moving strictly along gridlines. This is what I am interested in for my games.
Are you talking about any angle with free movement and no grid? I don't think A* would be good for that, certainly. Or, are you talking about a case where you have a grid, but you'd like the chosen path to follow a straight line between the points as closely as possible, rather than going as far as possible along one axis and then as far as possible along the other axis? Sort of like asking for the path with as many changes of direction as possible, while still being as short as possible. I think you could probably fudge A* into handling that, but I'm not 100% sure…
Are you talking about any angle with free movement and no grid? I don't think A* would be good for that, certainly
Yes, I personally am interested in grid free movement, or an approximation using triangular or polygonal navmeshes.
I think you are narrowly focused on only your own use case of using pathfinding for only the player (one agent) when clicking to a location.
To be fair, this is @Solar_Flare 's thread with the intent of discussing the use case within his project. So this is kind of a moot point.
I am thinking bigger, with extremes like RTS gameplay where armies of units are pathfinding simultaneously.
Sir, this is RMW.
To be fair, this is @Solar_Flare 's thread with the intent of discussing the use case within his project. So this is kind of a moot point.
I answered in my first reply what I thought the best RPG Maker pathfinding plugins were. You also asked me what the issue with A* was so we went on that tangent.

Original thread: https://forums.rpgmakerweb.com/threads/smarter-pathfinding-plugin.179951/