Hi, I’m pretty new to A* and pathfinding in general so sorry for the beginner question…
To test out the pathfinding features I created a simple scene with a terrain and created a grid graph on top of it (no obstacles) using the terrain’s layer as the height mask. I added several actors using the AIPath script and when I move them short distances, everything seems to work as expected.
However I’m noticing some weirdness with the AIPath script when I select a target that’s a further distance away, sometimes the actors will loop back on themselves or just dance around without seeming to make any progress towards the target. I suspect this might have something to do with how the AIPath script tries to recalculate the path when the target is a long distance away, as increasing the interval between recalculating seems to reduce or eliminate the problem.
I guess my main question is what is the best practice for recalculating paths when using grid graphs with a distant waypoint or am I seeing some other aberration with the AIPath script?
After I posted this it occurred to me why this was happening by watching the scene editor as the actors are travelling. It appears to be occurring because the repath operation is taking a long time the further my actors are away from the target. So by the time the repath has finished the actor has moved well past the point where the repath was started (character’s position). So when the path is completed the character turns around, moves back to where they were when the repath was started and continues the process until they finally reach the destination.
I’m not exactly sure the best way of solving this kind of problem, however. How is this traditionally handled in pathfinding? It seems that I wouldn’t want to recalculate from my actor’s position but predict where to recalculate from based on the where the character will be when the repath finishes…
That is exactly what is happening.
The AIPath script has code to mitigate this (controlled by the “Closest On Path Check” field) but it can only do so much.
If you are using a navmesh (recast graph or navmesh graph) try using the RichAI script which can do this in a better way due to differing internal structures and assumptions (RichAI works only on navmesh type graphs and on grid graphs since that is technically a navmesh graph, but not as well).