Animation not changing when Vector3MoveTowards executes before previous animation finishes?

Hello friends,

I am trying to animate a dog that follows the Player and sits, stands, walks, or runs depending on the distance it is from the Player.

The issue: If the Player moves away from the dog too fast, then the dog stays in the sitting position but still follows the player, making it slide on it’s bum. See the video below:

See the script below:

    void Start () {
        animator = GetComponent<Animator>();
    }

    void Update()
    {
        float dist = Vector3.Distance(target.transform.position, transform.position);
       
        if (dist >= runDistance)
        {
            Run(animator);
        }
        else if (dist >= stopDistance && dist <= runDistance)
        {
            Walk(animator);
        }
        else if (dist <= sitDistance)
        {
            Sit(animator);
        }
        else {
            Stand(animator);
        }

    }

    private void Stand(Animator animator)
    {
        Reset();
        animator.SetFloat("Movement_f", 0f);
    }

    private void Sit(Animator animator)
    {
        animator.SetBool("Sit_b", true);
    }
   
    private void Walk(Animator animator)
    {  
        transform.position = Vector3.MoveTowards(transform.position, target.transform.position, walkSpeed * Time.deltaTime);
        animator.SetFloat("Movement_f", 0.5f);
    }
   
    private void Run(Animator animator)
    {
        transform.position = Vector3.MoveTowards(transform.position, target.transform.position, runSpeed * Time.deltaTime);
        animator.SetFloat("Movement_f", 1.0f);
    }

    private void Reset()
    {
        animator.SetBool("Sit_b", false);
    }
}

Question: How can I get my dog to stand up before it starts to follow the Player?

There’s most likely something wrong going on in your animator transitions.
You could post a screenshot of your Animator.

Also, you might want to rename your function Reset () to something else. Unity calls this function in the editor.

1 Like

Thank you for the Reset() advice, much appreciated.

I’m using Animations from a package from Synty Studios (PolygonDog). I tried to add images but they wouldn’t load? So I’ve linked to them (sorry).

See the Animator image:

The Locomotion state has a blend tree with the Stand, Walk, and Run animations. See image:

The Sit sub-state machine look like this:

I would just watch the animator when the issue occurs to see what triggers and bools are being set. I don’t see them in the screenshots.

wait for it to transit fully from sitting into walk/run state, then use movetowards