Navmesh cut and checking if the path is valid with RichAI?

I have a navmesh cut component which i use to represent a locked door. And a character using RichAI.

Yet when i set a target which is behind the door, i want to check its reachable on the nav-mesh. And if its NOT reachable - do nothing.

So i was trying this method:

void OnPathComplete(Path p) { Debug.Log(PathUtilities.IsPathPossible(p.path)); }

But it’s always true. This is because seeker is finding the “nearest on node”. As shown in the attatched image. But if you look at image, my nav mesh cut has seperated the navmesh, so its not a valid path to true target so i want my character to not walk at all.

So how can i stop him navigating at all if he cannot reach his target.

Note: I still need to use nearest on node when there is a valid target for when the target happens to be off the mesh slightly due to user click accuracy.

I read the documentation but i could not find the relevant information.

Please help as i have been trying all night to get this to work.

Ok i found a solution but i don’t know if there is a better approach.

My method of solving this was to use:

if (Vector3.Distance(target, p.vectorPath[p.vectorPath.Count - 1]) > 1f) //invalid path

In the RichAI. Wondering if this is the best way or if there is a more efficient built method that essentially does what i did here.

Hi

You probably want to do something like

var node1 = AstarPath.active.GetNearest(sourcePosition, NNConstraint.Default);
var node2 = AstarPath.active.GetNearest(targetPosition, NNConstraint.Default);
Debug.Log(PathUtilities.IsPathPossible(node1, node2));

When you run PathUtilities.IsPathPossible(path) then you are essentially just asking “is it possible to traverse this path that was just calculated”, which is obviously possible since it was just calculated and must therefore be a valid path.

@aron_granberg thanks for the reply!

I see my mistake that makes sense now :slight_smile:

Though i still have some issues In my UpdatePath() for RichAI i put:

if (PathUtilities.IsPathPossible(AstarPath.active.GetNearest(transform.position, NNConstraint.Default).node, AstarPath.active.GetNearest(target, NNConstraint.Default).node)) { seeker.StartPath(transform.position, target, OnPathComplete); } else { //abort current RichAI path seeker.GetCurrentPath().Error(); //not working }
The problem is, when i try to abort the current path so the NPC stops. He seems to walk in an infinite straight line at a very slow pace. So i am wondering if Error() is the wrong method to abort/cancel?

You can see the effect below, he walks to the door, then i lock the door (notice navmesh turns red showing a seperate area, the Error() calls and he then walks very slowly in a straight line ignoring everything (he will walk for infinity if i leave him to it) wondering if this is a bug or i am using the wrong method?

Hi

Hm… I am not sure what would cause that.
Are you using an RVOController on the character? Maybe there is some bug that causes it to not reset the velocity to zero if it cannot calculate a path.

Note that what you are doing to abort the path will abort the path calculation, not necessarily movement.
I would instead suggest that you set the target position to the current position of the character or something similar.
E.g

seeker.StartPath(transform.position, transform.position, OnPathComplete);