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".