A* Pathfinding Project

Detect if RichAI is on Recast Graph


#1

How can I detect that the RichAI is on a valid node in the Raycast Graph?
thanks


#2

Hey,
You can use the AstarPath.active.GetNeares function.
https://arongranberg.com/astar/docs/navgraph.html#GetNearest
And check the distance to the agent.


#3

Hi

The RichAI will always be on the recast graph. Every frame it is snapped to the closest point on the graph.


#4

Also when isStopped=true ?


#5

Yes. It will be clamped to the navmesh in that case as well.
The only requirement is that it needs to have a path. So in the beginning of the game when the agent’s destination is not yet set it will not do this. But once the first path has been calculated it will start doing it.


#6

It’s not expensive if I have ~100 agents?


#7

In some cases I don’t have a path… any other cheep way to detect this?


#8

You could use

bool onTheGraph = AstarPath.active.recastGraph.PointOnNavmesh(agent.position, null) != null;

#9

Works great!!!
Thanks