Animator controller problem

Hi!

I am trying to make a simple scene with a Player (controlled by the user, third person, from Unity Standard Assets) and an NPC who wanders in an selected area. I made an Animator Controller and attached it to the NPC. In the Animator Controller are two animations Idle and Walk, I added to Parameters “Speed 0.0”, and transitions from Idle to Walk and from Walk to Idle.

The problem is when I press play, the NPC uses only the default animation (in this situation it is the Idle animation). When he walks and is idle, only the Idle animation plays.
I want to make that when he walks he uses the Walk animation and when he is Idle for a few seconds, he uses the Idle animation.

I guess I need to define somewhere in the script what Speed is, so when Speed is > NPC uses the Walk animation and when Speed is < NPC uses the Idle animation, but I don’t know how.

Can someone please help me, thank you!

you need to update the speed value in a script attached to the object like this

//this will hold the reference to the animator
private Animator myAnimator;

//we will use this to know how far the gameobject has moved
private Vector3 posLastFrame = Vector3.Zero;

void Start()
{
       //we create the reference to the animator attached to this game object
        myAnimator = GetComponent<Animator>();
}

void Update()
{
      //we work out the speed by (difference in positions) / framerate
     // this will give a speed in m/s
      Float speed = ((transform.position - posLastFrame).magitude) / time.deltaTime;

     //this is the important bit
     //SetFloat will look for a veriable by string what ever you called it
     // and will set it to the float
      myAnimator.SetFloat("Speed", speed);

   
}

void LateUpdate()
{
 //save this new position to be used next frame.
        posLastFrame = transform.position;
}

also this willl list all the functions and veriables for the animator along with all the other classes in unity… well for the most part