A* Pathfinding Project

When setting a destination that is blocked, check when NPC has reached end of path


When I set a destination that is blocked, the NPC will move as close as it can to that destination, then stop when it gets to the block. Great!
Now I want to run some logic once an NPC reaches that point. Is it possible?

I know you can check if you can reach point B from point A, but that is done before setting the destination, which is not what I want.

Thank you for all your help :slight_smile:



This is a surprisingly tricky thing to define. For example, if the destination is 1 meter above the surface of the navmesh, is that point considered reached if the agent moves to the ground below it?

The easiest way I have found is to do a check for if the agent has reached the end of its path and if it is reasonably close to the point it wants to reach.

if (ai.reachedEndOfPath && Vector3.Distance(ai.position, ai.destination) < ...)

Depending on your game you may want to only check the X and Z coordinates of the distance to the destination.

[Edit] Upon reading your question again, I realize that you might just have been looking for ai.reachedEndOfPath.



No I already knew about ai.reachedEndOfPath. But I think using:

Vector3.Distance(ai.position, ai.destination) 

I can figure out a neat solution :slight_smile: