How do I check if my character is inside Navmesh?

I am moving my character using transform.translate , but I still need to know if I can make my move depends on if predicted position is still inside the navmesh. Is there way I can say ray cast down to check for something or call some API function to see if I am (or will be) inside the navmesh?

Hi

You can use the
AstarPath.active.GetNearest method to get information about the nearest node.

var nn = NNConstraint.Default; nn.distanceXZ = true; // More closely emulates a ray cast downwards var info = AstarPath.active.GetNearest ( myPosition, nn ); Vector3 closestPointOnNavmesh = info.clampedPosition;

If you know you are using a recast graph, there is also this method
if (AstarPath.active.astarData.recastGraph.PointOnNavmesh (myPosition, null) != null) { // On navmesh }
However this might be unstable to use since when a character is moving along the edges of the graph, it might be outside the graph by a really really tiny amount (e.g floating point errors) and then this method will return false.

Ok it seems to work ok, but I have case where I have one grid and one recast graph overlapping in some places.

When my player is at the edge of the one graph ( that continues to the other graph and overlapping) the value I sometimes get is the value clamped by the one that is inside the other graph. meaning even the other graph tends to continue it thinks the nearest point clamped is the one from the other graph.

When I have situation like this, how can I go on about it so that the result I get is sort of “OR” operation? meaning, the graphs should behave like additive to each other, so when they are overlapping it still is valid graph and only clamp if the position is non overlapping at all?

Actually, having closer look at the issue. The clamp seems to happen at the border of the grid graph. Not actual generated grid but the graph size border. (white lined)

If my character is moving fast enough, it can by pass the border, but if not it gets sometimes stuck there.

Multiple graphs is always very tricky.
I am sorry, but there is not much I can do about it.
You could try using the graphMask field on the NNConstraint to check the distance to the individual graphs, maybe that could help you.

Humm… if I can check the distance to the individual graphs, perhaps I could then calculate the furthest point and use that one to see if I am still inside any of the graphs.

Can you show me example of how to use NNConstraint to do this?

Hi

var nn = NNConstraint.Default; for ( int i = 0; i < graphCount; i++ ) { // Find distance to graph i nn.graphMask = 1 << i; GetNearest (..., nn); }

And I guess the way I can find how many graphs I have in the scene is by checking :

AstarPath.active.graphs.Length ?

Exactly.
(well, I guess you would know as well since you built the level, but yes)