Animation controller example
displacement = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
displacement = Vector2.ClampMagnitude(displacement, 1);
rb.velocity = displacement * Time.deltaTime * walkSpeed;
animator.SetFloat("WalkSpeed", rb.velocity.magnitude);
if (displacement.magnitude > 0.1f)
{
animator.SetFloat("XSpeed", displacement.x);
animator.SetFloat("YSpeed", displacement.y);
}
- Here, we set three properties:
- WalkSpeed is used to transition between PlayerIdle and PlayerWalk blend trees
- XSpeed and YSpeed are used to choose direction in the blend trees
- Note that we don't reset them when movement stops!