Detecting when off of RecastGraph

(Currently using 3.6.0.0)

There are moments in our game where external forces (physics impulses/“knock-backs”) can possibly move our agents off of the RecastGraph’s mesh. This leads to agents being “stuck” on walls. Is there any way to detect that this has happened?

I was thinking I could simply grab the mesh data from the RecastGraph (it does not look like it is exposed, or if it is, I can not find it) and do raycasts to detect that the agent is no longer on any node on the navmesh. Once this condition has been detected I can simply move them back to the closest valid place on the navmesh.

Any thoughts?

Thanks in advance.

Hi

Check out the RichAI movement script, it will automatically clamp the agent to the closest point on the navmesh.
Otherwise you can check out the NavmeshClamp script.

Thanks for the speedy reply, Aron.

It doesn’t look like there is any NavmeshClamp script included. Was that added post 3.6? I’ll look into RichAI, however we’ve already invested a significant amount of time building on top of AIPath for our agents and am not sure if we can easily walk back at this time. I’ll take a closer look see if I can’t put anything together.

Thanks!

Ok. I will just post it here then: http://pastebin.com/1zLr8xQz

Hmmm, this seems to prevent an agent from leaving the nav mesh, however, I am more interested in the moment when an agent leaves the navmesh so that I may solve it more elegantly than simply “snapping” the agent to it.

This also raises an interesting concern with what Recast is generating, as seen here: http://i.imgur.com/3hvRv8k.png

Each one of those blue/grey checkered boxes has a RecastMeshObj attached and set to be Unwalkable (-1). This may be similar to this issue: Preventing Recast Graphs Nodes inside Obstacles

Moreover, if an agent happens to fall into a spot between the navmesh and those little orphaned pieces, I may be getting false positives attempting to snap agents to those rather than the correct navmesh.

Thanks again for the assistance.

Hi

Yeah, what you can do is that you store the last node that the player was in, and then you make sure that the node you snap to has the same “area” field. If two nodes have the same area field that means there is a path between the nodes.

You can also use the area in an NNConstraint that you pass to AstarPath.active.GetNearest btw.

Ah, I see. I believe I can resolve this with that information. Thank you.