Support Forum

How to check if a Vector3 point lies within a recast graph mesh

Hi All,

The title says it all really. I am trying to pick random locations for an ai to path to, but i need to check if the destination point lies within a valid recast navmesh. the navmesh has holes, so the ai might pick a position that is outside the navmesh and over a hole, i need to be able to raycast against the navmesh or something to see if its a valid destination. Can you advise?



When calculating a path, it will find the path to the nearest point which lies on the navmesh.

You can find the nearest point on the navmesh like (myPosition).clampedPosition;

You can check if a node lies on the navmesh when seen from above (sort of like a raycast down).

var graph =; if (graph.PointOnNavmesh (myPosition, null) != null) { // Inside the navmesh }