Startpath() not returning the best path

Hi Aron,

So this is weird. I’m using tags to block off nodes from being selectable by seekers. So that, for example, two entities do not try to occupy the same space.

So now, I have a player, and when he selects an enemy, it calls “StartPath” on the two positions, knowing full well that the end position is blocked, but believing that it would return the shortest path between the two points. However the results are very odd indeed.

in this first photo, everything appears correct…

but as you can see, from the other side, the seeker returns the same final position, even though there is a node two squares closer.

Thoughts?

Hi

This is because when a path is requested, it will first pick the closest point it can reach from the point you requested and then find the best path to that point. This is done for performance since otherwise some path requests might have to search the whole graph just to conclude that the path it found was the best one.
To solve this problem you could either not make the target point unwalkable and then just remove the last node or you could use the MultiTargetPath which properly handled multiple different target points.

so why in the 2nd example is it not returning the closest point, if the goal is to “pick the closest point it can reach from the point you requested…”? That’s what I don’t understand. In the original version of my game, we in fact did things the way you are suggesting to do them, which is we would make a node walkable, then grab pathpoints-1, but for some reason I didn’t think this would return funky results like this.

It will pick the point closest to the target point that you requested.
Around the target point there are in this case 4 nodes which are equally far from the target point, so it will pick one of them arbitrarily. Or more likely due to floating point imprecision one of the points will actually be very very very slightly closer than the rest (which is also another reason it was implemented in this way. There is usually one point that is slightly closer to the point you requested. Remember that the system does not just handle grids but can also handle navmesh and point based graphs and it needs to handle them in a similar manner).