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.
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.
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.
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.
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.
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.