- Home /
How do I run two animations at once on the same game object?
I have a walk animation and a gun animation. I want to be able to wield the gun, and walk at the same time. Is there any way to do this?
EDIT: Please help me with the comment I just made on SilverTabby's question.
Answer by SilverTabby · Aug 28, 2011 at 12:59 AM
You need to use Animation.Blend
By blending two animations together, you can achieve the result you are looking for.
Blending works by taking the bone movements of the first animation, and averaging those movements with another animation based on the weight value - creating a smooth result of the animations
Using blending, you can both walk and talk at the same time, or move from an active animation to an idle animation smoothly, and many other things.
note: 0 and X averages to X, so blending a head bob with walking will not make you walk slower
You won't walk any slower, but the strides will be averaged with the other motion, like you said. An all-bone walk blended with an all-bone head-bob gives short half-strides and half the headbob. X degrees averaged with 0 degrees gives X/2 degrees.
Now, if headbob was created only on head bones, I'm not sure what blending does to the feet.
Can you give me an example of blending two animations? I'm still pretty new to Unity. (I read the Animation.Blend page, but it didn't really give any examples)
Set one on a higher layer (they are normally on 0) and give it a weight less than 100%. In this, bob plays at 40% and walk gets the rest:
animation.Play("walk"); animation["bob"].layer=1; animation.Play("bob"); animation["bob"].weight=0.4f;
Answer by Owen-Reynolds · Aug 28, 2011 at 01:47 AM
Three ways to continuously combine two animations. See the unity animation docs for examples. Either of the first two should work for you. #1 is easiest:
o Limit them (using AddMixingTransform) to various bones. Could play walk, and play gunAim over it (on a higher layer) limited to arms only.
o Add one to the other. Suppose walk has the arms in rest pos, but swaying a little; and run has them in rest, swaying more. Can set gunAim as as Additive animation, and play on a higher layer. You'll get the walk arm-sway, with the gun aim added to it. Can also use the limit-to-bones trick. Problem with this is the animator had to plan for it.
o Blend/Average them. This plays them half and half (or whatever ratio.) It always looks bad unless the two animations are extremes of the same general motion. For example blending "big arm pump" with idle in bigger percents as you run faster.
Your answer
Follow this Question
Related Questions
FPS Multiplayer character animation / behaviour 0 Answers
How to set legacy on an animation? 1 Answer
Directing character's fist to a specific position 1 Answer
Character Animation Import Problem 0 Answers
Base Model Animation 1 Answer