Instead of animating a character in an inactive(Idle) state.
After a while the animation works again:.
Exit time is disabled for transitions.
Player Controller file code:
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
public Animator animator;
Vector2 movement;
private Rigidbody2D rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.sqrMagnitude);
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement.normalized * moveSpeed * Time.fixedDeltaTime);
}
}
Horizontal and Vertical parameters: Animator Window Animator Window
Here are the transitions between the idle state and the running state (Movement): Animator Transition Idle -> Movement Animator Transition Movement-> Idle
After the speed parameter becomes greater than 0.01, the character goes into the running state(Movement), if less than 0.01, back to the idle state.