- Home /
Using Unity Navigation in a fixed timestep
I want the navigation to have some semblance of determinism so it can be used for multiplayer. I'm using CalculatePath instead of SetDestination so there can be a synchronized start. The problem is running navigation in a fixed timestep so it can interact with the rest of my multiplayer game and be more deterministic. Is there a way I can run Navmesh Agent with FixedUpdate instead of Update?
Answer by DanSuperGP · Jan 31, 2015 at 12:11 AM
Your best bet is to set NavMeshAgent.UpdatePosition and NavMeshAgent.UpdateRotation to false. Then the NavMeshAgent will do the pathfinding but no longer control the motion of your characters.
You can then control the position and rotation of your characters yourself using animation or physics code and just use the NavMeshAgent for the pathfinding portion. You can access the NavmeshAgent.path property to get the NavMeshPath.
You will need to write some code to keep track of the path and control your movement, but I suspect this is what you really want anyway.
There is a functional difference to be aware of between Unity 4 and Unity 5.
In Unity 4, a NavMeshAgent with UpdatePosition = false will still internally keep track of it's position.
In Unity 5, a NavMeshAgent with UpdatePosition = false will not internally keep track of it's position. When you move the agent you need to manually update the position by setting NavMeshAgent.nextPosition
If you look in the documentation for Unity 4 and Unity 5 you will notice that there are changes to the documentation of NavMeshAgent.nextPosition
Oh...
Just to mention... I'm pretty sure if you have UpdatePosition and UpdateRotation set to false, you can use DesiredVelocity to tell you where it wants to go.... and it will update with the path as long as you keep it's internal positional tracking updated (which only needs to be done manually on Unity 5)
Oh, thanks a lot! Is it possible to use this method and also take advantage of the crowd control as well?
Yes, essentially it is still doing everything except actually changing the position and rotation of the Agent. So if it's trying to do crowd avoidance and the like... it will be reflected in DesiredVelocity.