So we’ve been trying to animate a character with blended animations between his upper and lower body. Essentially we’re trying to do things like having his legs continue running while his upper body shoots when you click. Should be easy, but having some difficulty.
Has anyone gone about doing this before? The problem we’re having is that the upper body animation is taking some of the bone positions from the lower body, and thus isn’t lining up and looking right. We’re blending two separate animations, one which is the lower body running with no keyframes on the upperbody, and the other is the upper body shooting with no keyframes on the lower body.
Does anyone know if there’s a way to assign an animation to a specific bone or group of bones instead of the entire gameobject? Or better yet if there’s a way to assign animation weights to only certain bones in the skeleton, so we can force it to ignore the wrong anims.
Thanks for any help!
tl;dr Is there a way to assign animations or weights to individual bones in a skeleton instead of to the entire gameobject?
I’ve done exactly this when I was writing the character code for Project Weasel… you can achieve the result by restricting an animation to a particular sub-hierarchy of the skeleton.
So if you’ve got something like this:
var animationTarget : Animation; // the thing with the Animation attached to it
var upperBody : Transform; // points to a bone containing the upper body (e.g. small of back)
// SETUP (e.g. inside Start() )
// You assign the animation to a separate layer
animationTarget[“shoot”].layer = 10;
// And use AddMixingTransform to restrict it to your subhierarchy
animationTarget[“shoot”].AddMixingTransform(upperbody, true);
// EXECUTION (e.g. inside your Fire() coroutine)
// Later, when you fire, you do it fairly normally:
animationTarget.CrossFade (“shoot”);
Note that this may not always be what you want… e.g. you may have a shoot animation that CORRECTLY uses the lower body, which makes sense when the character is stationary, but not when it’s running, or whatever. In such cases you may want to have two different shoot animations, one layered and with AddMixingTransform OR use AddMixingTranform only when needed (I don’t have experience with that, but I assume it’s doable).
That sounds perfect! Thanks for the help, we’ll go give it a try.