How to prevent an animation from interfering with NavMeshAgent movement?
I downloaded a simple asset from the store that is supposed to provide some animations for humanoid characters. It comes with an animation controler (Mecanim).
The problem: I can't use it with NavMeshAgent. As long as the animation is set to Idle, everything works fine - after issuing NavMeshAgent.destination = somegoal my character runs (er.. slides) to that goal and stops.
But if I set the animation to make the model run, my character will no more reach its goal, but rather it will run circles around it endlessly.
What I really, really fail to understand is why this keeps happening even though I explicitely set NavMeshAgent.updatePosition and NavMeshAgent.updateRotation to true? The way I understand the documentation, this should force the character to move as the NavMeshAgent wants it to move, not as the animaiton wants it to move!
Here's my very simple code:
public class MoveDestination : MonoBehaviour {
public Transform goal;
private NavMeshAgent agent;
private Animator animator;
void Start () {
agent = GetComponent<NavMeshAgent>();
animator = GetComponent<Animator> ();
agent.updatePosition = true;
agent.updateRotation = true;
agent.destination = goal.position;
animator.SetBool ("Moving", true);
animator.SetBool ("Running", true);
}
void Update() {
if (agent.remainingDistance == 0) {
animator.SetBool ("Moving", false);
animator.SetBool ("Running", false);
}
}
}
How to fix this?
Answer by gaazkam · Apr 23, 2016 at 03:26 PM
The correct answer to this problem comes from StackOverflow, http://stackoverflow.com/a/36784543/4385532 . It reads:
Do all your animation in place and use code to do the movement and you can uncheck root motion and use state machine values to get a better movement or use root motion and let mecanim`s retarget engine do the blending so go see for yourself what gets you better result , so I guess your problem is that your animation are not in place.
Yes, unchecking Apply Root Motion
worked for me like a charm.
I'm having a similar issue except my Animator says Handled By Script
in the place where I should be able to uncheck root motion. Not having much luck googling.
I unchecked root motion and set my animation as "In place". the character is now animated but it doesn't move from point A to point B. RigidBody.movePosition(...) stopped working.
Your answer
![](https://koobas.hobune.stream/wayback/20220612075214im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Having issues with teleporting forward 0 Answers
Animations get screwed up when I add OnAnimatorMove function 0 Answers
My player does not turn around 0 Answers
Mecanim Generic No movement 0 Answers
´How to check if 3D player is moving? 0 Answers