Navmesh Agent velocity VS physics

I’m making an RTS game demo with Navmesh agent. I tried to move many characters to a point at same time. They can collide and avoid each other, also calculate their positions automatically, just like Warcraft.

According to the document:

You can use a NavMesh Agent to move e.g. a player character, without physics
Set players agent’s avoidance priority
to a small number (high priority), to
allow the player to brush through
crowds Move the player agent using
NavMeshAgent.velocity, so that other
agents can predict the player movement
to avoid the player.

My code:

void OnAnimatorMove() {
	GetComponent<Rigidbody>().velocity = agent.desiredVelocity;
agent.updatePosition = false; has been already set.

I’ve also tried to switch on/off of character’s “Is Kinematic” in rigidbody. The problem is, if “Is Kinematic” == true, you can not set its velocity since it’s not affected by physics engine. If “Is Kinematic” == false, the nav mesh agent will not work correctly since a race condition happened. So, I don’t know how to implement “move a character without physics” described in this document. Please help.

P.S. I’ve made a demo here with test case for reference, single character movement is fine but multiple characters will cause some issues like nav mesh agent didn’t function well after colliding.

You need to setup things like:

  • Your rigibody IsKinematic must be set to FALSE, so you can move the character.
  • You need to freeze rotation in your rigidbody to avoid the character falling.
  • You need your Animator with Rootmotion = true.
  • You need your navMeshAgent updatePosition = true and updateRotation = false.

Then what you need to do is:

Get the desiredVelocity of the nav
mesh agent. Use this velocity to
change animator parameters to move
forward and turn around.

despite of having enabled
rootmotion, you will have to rotate
your character manually using
Transform.Rotation so you can rotate

Finally, in the event
OnAnimationMove you need to get
Animator.deltaPosition and use it to
get the velocity and set it to your
character’s rigidbody.