AI NPCs going back and forth (searched forum already)

Hello Aron,

I’ve already searched here and found no real solution for what I have (or only too old answers).
With just one NPC on the map, if I send him to a place that is far (3/4 of the map distance), in the middle of his way he goes back a few steps (I mean walking/moving) and then go forth again to his normal path. After a few seconds, this happen again and again. Only when it is near the target he stops doing this or if I send him to a closer destiny (not too far).

Can you help me to solve this?
I am using:
RVO Controller
AI Path
I put Simple Smooth, but that does not help anything.
Grid Graph (900x900 with node size 0.6) - tried already with much less, like 500x500 and node 1.0, same problem.
Connections: 8
Cut corners ON
Initial penalty 100000 (because I have roads, so I use it for gameplay)
Thread Count 4

This is really making me crazy, because I have no overhead, no problems with creating the paths and the grid (my map is big, but I imagine the impact should be on load the path, not really using it - and this is happening with just one NPC on scene).

The objects I have in the scene are all static (no objects moving while testing this). I’ve already tried changing Seeker Start End Modifier, AI Path’s “Pick next waypoind dist” and “End reached distance”, nothing really helps.

Aron, please, any lights here? =)
I really can’t solve this.


Sorry for the late answer.
This is due to the character having moved some distance while the path is being calculated, so when the calculation finished the character is no longer at the start point of the path. The AIPath script has some code to mitigate this if you have closestOnPathCheck enabled (which is the default).
I am thinking that your paths might take a really long time to calculate because you have a very high initial penalty. The higher the penalty, the more nodes have to be searched to make sure the shortest one is found. Check the console (and make sure you have path logging enabled) to see how long the paths take to calculate.

Hi Aron, thanks for the reply.

I was not using the high initial penalty, but I’ve read somewhere that it needs to be that high to be able to use it for something like a “road system”. So, do you think I can use a smaller number and it will work? And yes, I am using “closestOnPathCheck” enabled.

I just tested it, it does not look like it is taking too long:
“Path Completed : Computation Time 698.17 ms Searched Nodes 159416 Path Length 650
Path Number 429 (unique id)” Tops at 800, sometimes it appears as “0.00 ms”…

I tested sending the NPC in the other side of the map. I also changed the initial penalty, now it is just 1 (I think that’s default when we first launch A*). Looks like it is better, but even so, it is still happening.
EDIT: no, not better, sometimes it works better when it is half of the way I’ve sent =/

700 milliseconds to calculate a path is a very long time. Even 70 milliseconds is a long time. Do you think it would be possible for you to use intermediate targets so that the agents do not request paths that are that long? Or maybe use a recast graph instead? Or use heuristic optimization (if you are not modifying the graph during runtime).

Hi Aron

Yes, I could use intermediate targets, I will just need to think a good way of doing this (if you have any ideas, let me know please).
I can use recast graph, but I need to learn. Is there any big differences between grid? Do you have a good tutorial?
I will take a look on heuristic optimization.

There is a tutorial about navmesh and recast graphs here: (second part is about recast graphs).