- Home /
Why does an additive animation not play correctly when no other animation is playing?
In my project I am currently trying to setup a system where I have a set of animations for the upper body of my character and another set of animations for the lower body of my character that I play at separate times. The way I tried to do this was by playing by lower body animations on one layer and then playing my upper body animations, that I had changed to be additive, on a higher layer. This works very well except when there is no animation playing for the lower body and I try to play an animation for the upper body only. When I do this the animation seems to rotate and move a lot more than normal, and appear much different from how it plays normally.
Here is an example of code where I am having this problem:
function Start (){
animation["Attack"].blendMode = AnimationBlendMode.Additive;
}
function Update () {
if(Input.GetKey(KeyCode.G)){
animation.Play("Attack");
}
}
Any information on this would help a lot. Thanks.
Answer by Owen-Reynolds · Mar 25, 2013 at 06:06 PM
The official way to have top half / bottom half animations is to cut-out bones using AddMixingTransform (or maybe you can check them off now, in the Inspector.) Then play the animations as regular "blended" (not Additive.)
But, what you have should work. As you note, Additive always needs something else playing under it. So, create a "frozen" animation. Just grab 1-2 frames at the start of idle, and have it loop. Then never stop the lower animation, instead, Play/CrossFade to frozen.
I was about to reply an say that I had already created a "frozen" animation to play under it, however your comment made me realize that I was accidentally stopping the "frozen" animation when I would play the attack animation. Thanks for the reply.
Answer by Griffo · Mar 25, 2013 at 05:34 PM
Have you tried using CrossFade, just a thought, if your main animations are a walk or run then if the attack animations are only top half then it should CrossFade nicely, I find this a good way if you are doing your own animations.
function Update () {
if(Input.GetKey(KeyCode.G)){
attack();
}
}
function attack(){
animation["Attack"].layer = 2;
animation["Attack"].wrapMode = WrapMode.Once;
animation.CrossFade("Attack");
}
function walk(){
animation["Walk"].layer = 1;
animation["Walk"].wrapMode = WrapMode.Loop;
animation.CrossFade("Walk");
}
Also this might be your problem -
http://docs.unity3d.com/Documentation/ScriptReference/AnimationState-weight.html
I have tried using CrossFade before, however, unless I make the blend$$anonymous$$ode of the attack animation Additive the walk animation is not played as the attack animation is being played on a higher layer and takes priority.
I had not thought about the weights of the animations being the problem, but I have tested this and the animations all seem to be weighted correctly.
The animation docs describe a specific top/bottom trick that lets you mix&match leg/arm animations. You might animate walk/run/idle/kneel only for legs, and shoot/punch/throw/idle only for arms; and be able to pick run+punch.
It looks like the OP is going from that.
I currently have the animations for the upper body only animate parts of the upper body, and the same for the lower body.
Your answer
Follow this Question
Related Questions
animation play in game over 1 Answer
Animation Stop and Stay 1 Answer
Play animation when in collider and button pressed 1 Answer
Character won't play animation 8 Answers