Question by
somemilk · Apr 17, 2016 at 01:06 PM ·
animationnavmeshagentthird person controller
Animation not playing when moving third person character by navmeshagent
I'm using third person character controller from standard assets and I want to make it move to the target using navmeshagent. It moves just fine but movement animation does not play (it plays when I use control keys to control the character). I guess I need to play the animation manually but I can't figure how to do that exactly. Here's really simple code I used:
public class MoveTo : MonoBehaviour {
public Transform target;
Vector3 destination;
NavMeshAgent agent;
// Use this for initialization
void Start () {
agent = GetComponent<NavMeshAgent>();
destination = agent.destination;
// need to get some kind of Animation/Animator object here?
}
// Update is called once per frame
void Update () {
// Update destination if the target moves one unit
if (Vector3.Distance (destination, target.position) > 1.0f) {
destination = target.position;
agent.destination = destination;
}
// need to play animation here?
}
}
Comment