Posted March 17, 2025 by rqcoon
Back to what I was doing in class. The walking animation script! I made a new script that gets the animator and character controller components from the player, then during the update cycle it takes the current horizontal velocity and updates the animation accordingly. I also added in some variables for the animations playing speed, as well as the damping value to apply between the resting and walking animations. To hook this up to the animator, I simply made a new float condition to transition between walking and resting.
Animator animator;
CharacterController cc;
public float damp = 0.1f;
public float animSpeed = 1f;
...
Vector3 horizontalVelocity = new Vector3(cc.velocity.x, 0, cc.velocity.z);
float overallSpeed = horizontalVelocity.magnitude;
animator.SetFloat("Walk", overallSpeed, damp, Time.deltaTime);
if (overallSpeed > 0.1f) {
animator.speed = overallSpeed * animSpeed;
} else {
animator.speed = 1;
}
Great success!