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?