• Editor
  • Mixing Animations After Programmatic Change?

Related Discussions
...

I'm wondering if anyone has ever altered any bones programmatically, then tried to mix that state into another animation smoothly.

Our specific example is this:
We're programmatically rotating the torso of our spine model based on player input like so (cocos2d):

Bone *upperTorso = [hero findBone:@"torso_upper"];
upperTorso->data->rotation = TO_DEG(angle);
[
hero setToSetupPose];

And it works, as you can see in this image: http://imgur.com/MwYqisi

However, when we want to animate out of this state into another animation, the torso snaps back into place instead of tweening to the keyed rotation of the animation. I've tried to call addAnimationState and setMixFrom:to:duration: after setToSetupPose, but that doesn't seem to do the trick.

Does anyone know how this might be achieved?

First, you shouldn't need to call setToSetupPose. Changing the BoneData rotation is enough. Also, don't call findBone every frame, this does a strcmp for every bone.

When AnimationState crossfades, it applies the old animation (overwriting the pose for any keyed bones) then mixes the new animation. I believe what you want to do is apply the old animation, rotate the torso, then mix the new animation.

Since there is no way for you to run arbitrary code between the apply and mix inside AnimationState, you won't be able to use AnimationState to do what you want. AnimationState is only for convenience, you could track the times yourself and use the Animation API to do the crossfading.

Another option might be to modify the animation instead of manually adjusting the torso rotation.

Actually, it occurred to me that you are adjusting the BoneData rotation (ie the setup pose) not the Bone (ie the current pose). This affects all animations, so what I mentioned in my second paragraph wasn't right. In this case what you want to do is to set the BoneData rotation to point at your target, apply the old animation, set the BoneData rotation back to the setup pose, then mix the new animation. Everything else I mentioned still applies.

Changing the BoneData affects all animations. I guess your animation snaps back because you set the torso rotation to 0? If you leave the torso rotation, the next animation should mix just fine and be bent over in the same way. What you can do is, when you switch animations, adjust the torso rotation to zero over time so it doesn't snap.

Thanks for the quick response. I'm still wrapping my head around how the runtime works with BoneData and applying animations so I wasn't quite clear about how to execute what you suggested. I'll be reading up on the available documentation to get a better understanding and revisiting this issue, but in the meantime I've been able to get the results I wanted by manually adjusting the torso rotation in the update method.

Congrats on getting married, btw!

Thanks! 8)