How to safely teleport on NavMesh

I’m trying to implement a “Blink” teleport. Which moves the player x metres forwards. I thought this would be simple, as I’ve implemented it in Unity. However I’m getting issues where either the player falls through the landscape or is unable to move afterwards.

I’ve tried all sorts of combinations of SweepMulti, NavigationRaycast, ProjectPointToNavigation, FindPathSync (to get a path end point to the location instead; didn’t work), GetRandomPointInRadius (with a low radius), SetActorLocation and Teleport.

The issue almost always occurs when the teleport hits a wall (landscape), I find a point using combinations of the above to ensure it’s a valid navigatable point, and also adjust the position to be 2m away from the wall (which prevents most fall-through), but still it gets stuck all the time. Like it’s half-on the NavMesh.

In Unity I achieved the same by using raycasts and NavMesh.SamplePosition and never experienced this problem. I thought ProjectPointToNavigation was the equivalent but perhaps I’m wrong. Still learning!

Thanks in advance

Also running into a problem with a teleporting actor falling through the world (NavMesh).

Did anyone figure this out?

would you mind share your solution? when i teleport to target my character always through the floor …

I’ve made the same sort of mechanic work multiple times. If you are manually adjusting the endpoint to make sure you won’t teleport halfway inside the level geometry, it should work fine. The adjustment is the tricky part, so make sure you’re doing that correctly.

If you’re snapping your endpoint to the navmesh, then note that the navmesh is super close to the ground- and sometimes slightly under it- and your character’s location is usually at their center. So by teleporting to a point directly on the navmesh you’re probably teleporting them halfway into the ground, which is why they’re falling through. You need to teleport above the navmesh.

The full steps for what you’re trying to do would be:

  1. Calculate a position x units forward from your character.
  2. Project that location to the navmesh. (find closest walkable area)
  3. Raise that point up a moderate amount, say 50cm. (handle case where navmesh is slightly underground)
  4. From the previous point, raycast downwards. (find exact location of the ground)
  5. Add your character’s half height to the hit location to get your final teleport point. (adjust for character height)
  6. Set the character’s location to that teleport point.

This method is one of the simplest ways to achieve the effect, but some games might not work with the limitation of only being to teleport where the navmesh is. In that case, I hope you’re good at geometry.

1 Like