Recast navigation plugin: detect if point is in unreachable region of navmesh?

Hi, I’m trying to detect is a point is unreachable for an agent.
For example, I have a navmesh that has a tall box in it, of which the top is part of the navmesh, but there’s no connection to that top with the rest of the navmesh.
See for example this PG: https://playground.babylonjs.com/#WCSDE1#17

As in the PG, the top is (and should be for my use case) clickable, and when clicked the agents gather around the box as close to the clicked point as possible.

Is there a way to detect this state of agent, i.e.: the point given is valid on the navmesh, but there is no way for the agent to ever reach it?

Adding @Cedric to the thread

The unreachable mesh should be a different mesh. So you should be able to test onclick if current mesh !== target mesh then do something. Maybe raycast from target to closest edge of current and go there. You could also handle stuff like jumping or teleporting inside this logic. Idk if theres a more efficient way to check current, but easy way would be to just check the closest mesh to your characters/agent’s feet and/or keep a cached value on each successful or canceled movement command. Just thinking about it now, you could maybe even do some distance/direction check in the raycast to allow the character have a different animation like climb up onto a platform or jump down into a hole

Thanks for the reply, in my case it’s not meant for the player agent, but for (many) NPC agents, so I’d like to avoid a lot of raycasting and checking if I can to prevent fps drops. But I’ll check the seperate mesh selection, maybe that will get me a little further.

For my use case, some agents should be able to teleport to the clicked point (have teleport ability), and others should see that they cannot reach the requested position and should just stop trying to get there.

I was thinking there may be something possible with the crowd and the agent’s number of waypoints, but could not get it to work yet… seems like they just keep moving at the edge of the navmesh where the regions are cut off.

I think you can try to get it working by checking each position with raycast and remove later . The raycast from target wont be expensive because its only once per command, no matter the number of agents

Like:

class MyAgent {

get currentMesh () {
/*replace later by returning private _currentMesh property that gets updated on successful commands (will require its own debugging probably) */
Return this.raycastCheckingFunction()
}

raycastCheckingFunction(){ … }

}

Forgive any typos im on my phone lol.

Also maybe helpful to check the recast and detour docs. Its possible something useful there isnt exposed in the wasm module. recastnavigation/NavMeshTesterTool.cpp at master · recastnavigation/recastnavigation · GitHub

Ah one other thing, the idea to do raycasting from target to closest current edge and setting that as the new target is to stop the agents from infinitely trying. Just brainstorming

Did you try to compute the path with computePath and then, compare the path last position with the target postion? if they are too different, then it’s not reachable.

Thanks for your suggestions, I’m going to try and make it work!

1 Like