1

I'm using a few animations from mixamo, and have successfully implemented them to the unity animator, where I've set all the different states. A problem occours when I go from idle state to running state. The running animation is active for a few seconds, but then it freezes, until I stop the character, and it returns to idle state. Anyone got a clue what it might come from?:)

Here is the Move function and the functions for the different state from the code.

private void Move()
    {


        float moveZ = Input.GetAxis("Vertical");
        float moveX = Input.GetAxis("Horizontal");

        moveDirection = new Vector3(moveX, 0, moveZ);
        moveDirection = transform.TransformDirection(moveDirection);
        

       

        if (moveDirection != Vector3.zero && !Input.GetKey(KeyCode.LeftShift))
        {
            Walk();
        }

        else if (moveDirection != Vector3.zero && Input.GetKey(KeyCode.LeftShift))
        {
            //  Debug.Log("Pressed shift");
            Run();
           
        }
        
        else if (Input.GetKeyDown("space"))
        {
            Jump();
        }
        
        else if (moveDirection == Vector3.zero)
        {
            Idle();
        }

        moveDirection *= moveSpeed;
        controller.Move(moveDirection * Time.deltaTime);
      
    }

  
    private void Idle()
    {
       anim.SetInteger("state", 0);
    }

    private void Walk()
    {
        moveSpeed = walkSpeed;
        anim.SetInteger("state", 1);
    }

    private void Jump()
    {
       
        anim.SetInteger("state", 2);
    }

    private void Run()
    {
        moveSpeed = runSpeed;
        anim.SetInteger("state", 3);
    }

}

-I've already checked out exit time in the animator editor. -I've set all the animations to "Loop Time".

derHugo
  • 83,094
  • 9
  • 75
  • 115
Potato
  • 21
  • 2

1 Answers1

0

It might be better to use anim.SetTrigger("ParameterName") instead of anim.SetInteger() and simply call anim.ResetTrigger("ParameterName") to stop the current animation and then start a new one.

Also what it might causing your issue is that you use the same "state" parameter for all your animations.

It will be helpful if you can post a screenshot of your Animator screen including all the parameters that you have created.

Pavlos Mavris
  • 331
  • 1
  • 2
  • 12