- Home /
Animations are different when in lower layers
I have 4 animations made inside unity. Shoot IDLE ADS ADS OUT
The problem is that when I have my shoot animation on a layer above all the others, it plays the whole animation with all the curves set but it overrides all the other animations when playing.
Also, if I set it below the other animations or inbetween and even not a layer at all, the animation does not play the position change, If I can get the position animation to show with the shoot animation instead of just the rotation, that would be great!
Hope it wasn't confusing!
Here's the code.
var firerate = 2;
var adsspeed = 1;
function Update () {
//LAYERS
animation["IDLE MP5"].layer = 1;
animation["MP5 SHOOT"].layer = 2;
animation["ADS MP5"].layer = 3;
animation["ADS OUT MP5"].layer = 3;
//WRAPMODES
animation["MP5 SHOOT"].wrapMode = WrapMode.Loop;
animation["IDLE MP5"].wrapMode = WrapMode.Loop;
animation["ADS MP5"].wrapMode = WrapMode.ClampForever;
animation["ADS OUT MP5"].wrapMode = WrapMode.ClampForever;
//SPEEDS
animation["MP5 SHOOT"].speed = firerate;
animation["IDLE MP5"].speed = 1;
animation["ADS MP5"].speed = adsspeed;
animation["ADS OUT MP5"].speed = 1;
//BLEND MODES
animation["IDLE MP5"].blendMode = AnimationBlendMode.Blend;
animation["ADS MP5"].blendMode = AnimationBlendMode.Blend;
animation["ADS OUT MP5"].blendMode = AnimationBlendMode.Blend;
//SHOOTING
if (Input.GetButton("Fire1"))
{
animation.CrossFade("MP5 SHOOT", 0.5);
}
else
{
//IDLING
animation.Stop("MP5 SHOOT");
animation.CrossFade("IDLE MP5", 0.5);
}
//ADS
if (Input.GetButton("ADS"))
{
animation.CrossFade("ADS MP5", 0.05);
}
else
{
//ADS OUT
animation.CrossFade("ADS OUT MP5", 0.2);
}
}
Answer by Owen-Reynolds · Aug 13, 2011 at 05:52 PM
That code is running every frame. When you press FIRE, it fades into shoot for 1 frame, but next frame the ELSE says to resume idle. To see that, change to GetButton
-- holding fire should now play shoot. Instead of the else, you somehow want to say "play idle when fire is done running."
The common solution is to make shoot a "PlayOnce" (can use the Inspector,) and put it on a higher layer. Play idle in Start (or Awake) and never touch it again. Then have FIRE play shoot. Shoot will "cover up" idle, then fade out, uncovering idle (you will see it come back.)
Unity's AnimationIntroduction explains the whole layer and covering up idea.
No, that didn't work for me. The thing about the PlayOnce and layer part of the shoot animations is the aim down the sight animation. That would snap it back to the shoot animation if you hold aim and shoot down.
Your answer
Follow this Question
Related Questions
walk crossfade run animation based on joystick position need help please 0 Answers
Unity 3.5 Animation : stop one layer 1 Answer
Play an animation just on some parts of the body 1 Answer
Shaking skinned mesh animations 1 Answer
Animation: Impact of combining the use of Layer, CrossFade, and Weight 2 Answers