Some animations not looping how I want

Hello
I have a 2d player with 8-direction turning (I didn’t make the 8-direction turning script myself, but I made changes to it). In the script it tells which direction to go and which animation to play. Then when I stop pressing a key it goes to the one frame idle animation associated with it when the anim_over condition is on. All the animations have Has Exit Time turned off, also. My problem is that walking right, left, and up aren’t looping while I walk as the other 5 directions are and I’ve been unable to find a solution.

Video of What I mean:

https://vimeo.com/272644967

Full code for this:

using UnityEngine;
using System.Collections;

public class playerController : MonoBehaviour
{
    Animator anim;
    public float speed = 1f;
    private Vector2 movement;


    // Use this for initialization
    void Start()
    {
        anim = GetComponent<Animator>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        float inputX = Input.GetAxisRaw("Horizontal");
        float inputY = Input.GetAxisRaw("Vertical");
        movement = new Vector2(inputX, inputY);

        //Diagonals
       
        if (inputX != 0 && inputY != 0)
        {
            if (movement.y == 1 && movement.x == -1 && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("move_up_left"))
            {
                anim.SetTrigger("move_up_left");
            }

            if (movement.y == 1 && movement.x == 1 && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("move_up_right"))
            {
                anim.SetTrigger("move_up_right");
            }

            if (movement.y == -1 && movement.x == -1 && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("move_down_left"))
            {
                anim.SetTrigger("move_down_left");
            }

            if (movement.y == -1 && movement.x == 1 && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("move_down_right"))
            {
                anim.SetTrigger("move_down_right");
            }
        }

        else if (inputX != 0 || inputY != 0)                                                                 //These are the animations that arent looping...
        {

            //left/right/up/down
            if (movement.x == -1 && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("move_left"))
            {
                anim.SetTrigger("move_left");                                                                                                   
            }

            if (movement.x == 1 && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("move_right"))
            {
                anim.SetTrigger("move_right");
            }


            if (movement.y == 1 && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("move_up"))
            {
                anim.SetTrigger("move_up");
            }


            if (movement.y == -1 && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("move_down"))
            {
                anim.SetTrigger("move_down");
            }
        }
        else
        {
            anim.SetTrigger("anim_over");
        }


        transform.Translate(movement * speed * Time.deltaTime);
    }

}

The problem is almost certainly in the animations themselves (they need to have “Loop Time” set), not in the code or the animator.

But to save further headaches in the future, you might want to also consider this.

1 Like

This fixed it. Thanks!

1 Like