• Editor
  • Best way to setup mixing animations

I have a character that squats up and down but I want to have different animations for the same limb. i.e. Left leg has two different animations for the character squatting - and I want to switch between the two leg animations whilst the main animation of the character squatting is playing.

An example end effect I require is:

Character squats down
left leg gets shaky and uses 'shakyLeg' animation
left leg recovers and goes back to standard squatting animation
Animation finishes

The key thing is I need to be able to dynamically switch between the two animations on the fly at run-time.

If I switch between the two leg animations on the fly will the Spine C-API smoothly handle this? Or will it suddenly switch without any sprite position interpolation or similar?

I need this capability for several limbs/body parts (not just the left leg) and they need to have separate animations that can work independently of other parts of the body - yet still attach to the torso correctly obviously.

What is the best way to set this up in Spine? Anything special I should need to do?

Related Discussions
...

If using AnimaitonState it will always mix with the previous animation if you have set a mix duration between those animations.

Hi, dear Spine-team!

I'm also wanna know about the situations like this.
For example, my character can swim, but the legs of him should move uninterruptedly and independently of the rest of the body. I mean, something like this:
he swims, then something attacks him, immediately the head and the arms change their movings, but the legs should move as they moved before the attack without any delay or any strange abrupt changes of their movings.
How can we handle this?

You can use two animations, one for legs and one for torso.

Nate, do you mean to create two different spine projects and join them in the game itself?

It sounds like this is as easy to do as I had hoped. Thanks for the response.

Davlikanoff, no, you can just have 2 animations and apply them both each frame in your game. An animation only affects the bones and slots that are keyed.

Nate, does it means, that i have to create 2 animations inside one spine-project like following:
1 - the animation for the legs without torso (or with still staying torso)
2 - the animation for the torso without legs (or with still staying legs)
And then coder will join them both in the game itself.
Is it right?

Yes.

Also, you can have animation A that animates all bones and animation B that only some bones. Your coder can apply A and then B. B will overwrite the pose from A but only for the bone properties keyed in B, the rest of the bone properties won't be touched when B is applied.

Oh, got it.
Thanks for your quick reply!

11 jours plus tard
Nate a écrit

Yes.

Also, you can have animation A that animates all bones and animation B that only some bones. Your coder can apply A and then B. B will overwrite the pose from A but only for the bone properties keyed in B, the rest of the bone properties won't be touched when B is applied.

How does this work in C++(SFML)?
I've tried
AnimationState_addAnimationByName
Animation_apply
Animation_mix
but none of them are doing what Im trying to do. addAnimationByName shows Animation B, but animation A freezes, even the bones not keyed by B.

Trying to do exactly whats in the coding workshop with this line

bowAnimation.mix(skeleton, jumpTime, false, 0.85f);
Animation_apply(walkAnim, skeleton, walkTime, true);
Animation_mix(jumpAnim, skeleton, jumpTime, false, 0.85f);

That is for when not using AnimationState.

So is that not possible to do with AnimationState? From how I read your comment it looks like I need two timers to keep track of the where in the animations I am. I suppose this would cancel out the AnimationStateData_setMixByName, so to get similar mixing with this method it would all have to be done manually.
Thanks for all the help Nate, I promise I'll have something good to show in the showcase forum for all this trouble!

Edit:Just got it working using 2 AnimationStates! Ive been cross referencing this thread, and my code looks like this:

AnimationState_update(holdState, dt);
        AnimationState_apply(holdState, skeleton);
        Skeleton_updateWorldTransform(drawable->skeleton);

holdState being the second AnimationState. I'm calling that code after drawable->update, which from what I can tell is necessary.The one thing this doesn't give me is the ability to blend the animations with the alpha parameter, is there a way to get that with 2 AnimationStates? Is either the AnimationStates/no AnimationStates preferable to the other?

21 jours plus tard

Yup, you use 2 AnimationStates. AnimationState is just a convenience class. You can use animation directly if it doesn't do what you want. There isn't a way to blend 2 AnimationStates. You can apply one AnimationState and then use Animation_mix to blend another animation.