Unity3D - Changing animation states based on movement
<p>I'm trying to make a simple AI (a simple ellipse), which switches between a walking animation and a standing animation, depending on whether or not it is moving.</p>

<p>I already have the AI set to follow and turn to the player, however I am having trouble finding out how to switch between animation states.</p>

<p>I have a Boolean parameter in the animator, "<strong><code>isWalking</code></strong>", which is set to switch to the walk animation if <code>true</code>, and switch to the standing animation if <code>false</code>. </p>

<p>My problem is how to 'check if the object is moving'.
I essentially want to write some code that does something like this:</p>

<pre><code>If(object is moving) 
{
    isWalking == true;
}
else 
{
    isWalking == false;
}
</code></pre>

<p>I've searched on the web, but I've yet to find a solution.
I considered using <code>rigidbody.IsSleeping()</code> to see if the object is asleep, but I couldn't find any examples of how to use it.</p>

<p>I'm a complete newbie to both Unity and programming.</p>

<p>Thanks in advance. :)</p>

<p><a href="https://i.stack.imgur.com/wtQnD.png" rel="nofollow"><img src="https://i.stack.imgur.com/wtQnD.png" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/Slksf.png" rel="nofollow">The object, as shown in the inspector window</a></p>

<p>Edit:
I have tried this code, but there's probably something wrong with it. :/</p>

<pre><code>using UnityEngine;
using System.Collections;

public class aiscript : MonoBehaviour {

    NavMeshAgent agent;
    public Transform target;
    public Animator anim;
    Vector3 pos;
    public GameObject monmon;

    void Start () 
    {
        pos = monmon.transform.position;
        anim = GetComponent&lt;Animator&gt; ();
        agent = GetComponent&lt;NavMeshAgent&gt; ();
    }


    void Update () 
    {   
        pos = monmon.transform.position;
        Vector3 originalPosition = pos;
        agent.SetDestination(target.position);
        Vector3 difference = originalPosition - pos;
        anim.SetBool("isWalking", difference.magnitude &gt; 0.5f);
    }

}
</code></pre>