- Home /
How to stop a Navmeshagent from teleporting when the navmesh overlaps in Z
I've been trying to use the NavmeshAgent to create some minion characters that follow the player around in 2D sidescroller game.
One of the biggest issues I've found with this is that if a NavMeshAgent is pathing to a destination and passes a place where the Navmesh overlaps in the Z direction it will teleport in the Z axis to the destination instead of going around to the OffmeshLink which it should be using. Hopefully this picture will help you see what I mean.
I've noticed that the Navmeshagent will only exhibit this behavior if it either has no Rigidbody attached or the Rigidbody is set to be kinematic. However giving the agent a non-kinematic rigidbody adds a whole other set of problems where the physics and navmeshagent seem to interfere with each other.
Has anyone else experienced this teleporting behavior with navmesh areas that overlap in Z? Can anyone point out what I'm doing wrong here?
I've just experienced the same problem. And pretty much am in the same situation as you. Can't use rigidbody. I don't know enough about how unity's navmeshes work to figure this out, but hopefully someone else here can help us.
Answer by Tudor · Nov 13, 2013 at 11:32 AM
I seem to have found a workaround to the problem. I don't use off mesh links, instead I handle movement manually for the transition between two planes. So let's say I have my minion walk to the edge of the navmesh, then teleport to the other navmesh plane. But this way, it appears that when you teleport a minion to a new plane, the navmesh agent still thinks it is on the previous plane.
I couldn't figure out how to tell the navmesh agent which plane it should think it's on, but this is how to trick it to work:
//disable everything agent related
navmeshAgent.Stop(true);
navmeshAgent.updatePosition = false;
navmeshAgent.updateRotation = false;
//this is the most important part; turn the agent off:
navmeshAgent.enabled = false;
//do your nasty teleporting/flying stuff
teleportMinion();
//restore everything
navmeshAgent.enabled = true;
navmeshAgent.updatePosition = true;
navmeshAgent.updateRotation = true;
This should work regardless of where your two separate navmesh planes are in relation to each other.
I am still curious to see how to actually control how the agent decides to use the off mesh links, but for now this will have to do.
I had a strange problem after I positioned my charater object on the map and couldn't figure it out why it is teleporting before the first movement. $$anonymous$$y character teleported back to another position and started the first movement from that position if I did not disabled the Nav$$anonymous$$eshAgent while I modified the position of the object. Tudor you are great! Thanks man! I almost gave up to fix this and started thinking about other solutions... Thank you once more! I'm really happy now! :)
Your answer
Follow this Question
Related Questions
Movement with NavMeshAgent pushes RigidBody 1 Answer
Navmesh problem with characters rotation in the terrain 1 Answer
A little help with using Navmesh agents with RigidBody physics. 0 Answers
Is there a way to limit the size of a navmesh? 0 Answers
Navmesh agent does not operate after building the project 0 Answers