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
asked May 03 '14 at 05:21 PM in C++ Programming
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:
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.
Follow this question
Once you sign in you will be able to subscribe for any updates here