- Home /
This post has been wikified, any user with enough reputation can edit it.
Animation events play for all animations when blending?
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?
Comment
Best Answer
Answer by Brenden-Frank · Nov 08, 2012 at 06:05 PM
I ended up using anim.Crossfade() instead. It's a little less control but at least it isolates events.
Your answer
![](https://koobas.hobune.stream/wayback/20220613083445im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Play 2 animations at once 4 Answers
Play sound on animation event? 3 Answers
Doubled Animation Events In Blend Tree 1 Answer
how do u add sound clips to an animation using animation events? 1 Answer
Can't select function in Animation Event 9 Answers