I’m looking for a way to make my NPCs fall off a ledge (after being kicked by the player). They use NavMesh Agents for pathfinding.
I tried turning off the navmesh agent while it is being pushed, adding force to the attached rigidbody and re-enabling it a few seconds later. If they land on a surface without navmesh (like an edge) then they warp to the navmesh point directly below and it looks odd or sometimes get stuck in in-accessible areas.
Is there a better way to do this?
I think the first step should be to detect if the agent landed outside a navmesh. Maybe NavMesh.SamplePosition() can help with that, or maybe NavMeshAgent.FindClosestEdge() (the navmesh API is really bad at handling these situations).
Next, how would you like to handle the situation when the agent has landed outside? I assume you don’t want them to return at the closest point on the navmesh, because that is the current behaviour. What if they were killed, e.g. fallen off a cliff?