Is target inside nearest node area? (or even graph!)

Hi, i’m trying to figure out how I would check if my navmesh target is inside the navmesh area and I haven’t found a good solution yet. I know I can generate put my target back at nearest node center while generating one with Random.insideUnitSphere but I want to be able to return failure when the agent is attempting to get a node outside the graph, otherwise when the agent is close to a border or in a graph outer angle the chance of being stuck for the next movement goes from 50% to 75% which is very bad.

I’ll keep researching but any help is much appreciated!


“Inside the graph” is surprisingly hard to define well. What I’d recommend is to find the nearest point on the navmesh and check if that is close enough:

for example:

Vector3.Distance(, myPosition) < 0.5

You can also use RecastGraph.PointOnNavmesh to check if the point is on the navmesh when seen from above. But note that it will return that the point is on the navmesh even if it is hundreds of meters above the navmesh.

1 Like

Thank you very much! This is definitely useful :slight_smile: