I’m playing 3 animations:
//Prioritize the walking animation
anim["idle"].layer = 9;
anim["walk"].layer = 10;
anim["sprint"].layer = 11;
//Play all animations
anim.Play("idle");
anim.Play("walk");
anim.Play("sprint");
//Fade out moving animations
anim.Blend("walk", 0, 0.2F);
anim.Blend("sprint", 0, 0.1F);
I blend walk and spring based on the character’s forward velocity.
//
// In Fixed Update
//
if (velocity.sqrMagnitude <= sleepVelocity*sleepVelocity)
{
anim.Blend("idle",1,0.2F);
anim.Blend("walk", 0, 0.2F); //Fade out walking animation
anim.Blend("sprint", 0, 0.1F);
}
else if(velocity.sqrMagnitude > sleepVelocity*25)
{
//Fade in sprint animation
anim.Blend("sprint",1,0.2F);
anim.Blend("walk",0,0.2F);
anim.Blend("idle",0,0.2F);
anim["sprint"].speed = 1*animationSpeed;
}
else
{
//Fade in walking animation
anim.Blend("walk",1,0.2F);
anim.Blend("sprint",0,0.2F);
anim.Blend("idle",0,0.2F);
float animspeed = velocity.sqrMagnitude;
anim["walk"].speed = animspeed*animationSpeed;
}
I have events on walk and sprint that generate footstep sounds. However, I often hear events from both animations playing rather than just the heaviest weighted one. How would one deal with an issue like this?