ciaps

Dear Spine community,

After looking into every related topic on this forum, and using Spine for a couple months now, I decided to ask for help.

I do not seem to be able to mix animations properly in Unity.
Either:
  • My character has super weird poses, using setAnimation, OR
  • My character does not have any merged animations at all (using SetToSetupPose and ClearTracks before setAnimation)

The game is a point&click adventure, so the animation transitions should happen when the character starts walking, and stops walking.
I instantiated the character as SkeletonAnimation, not Mecanim, and my code looks like this (please read inline comments!)
void FixedUpdate() {
// I read the direction & speed parameters from an animator component
if (anim.GetFloat("Speed") != 0) {
int dir = anim.GetInteger("Direction");
// then, if speed > 0.1, I play a different animation according to the direction
switch (dir)
{
case 3:
SetAnim("walk_180_top");
break;
case 0:
SetAnim("walk_0_bottom");
break;
case 1:
SetAnim("walk_270_left");
break;
case 2:
SetAnim("walk_90_right");
break;
case 4:
SetAnim("walk_315_bottom_left");
break;
case 5:
SetAnim("walk_45_bottom_right");
break;
case 6:
SetAnim("walk_225_top_left");
break;
case 7:
SetAnim("walk_135_top_right");
break;
}
}
else
// if speed == 0, then I play some Idle animation.
{
anim.SetInteger("Direction", 4);
SetAnim("idle_315_bottom_left");
}

// While here I define the routine SetAnim

void SetAnim(string name) {

if (name == currentAnimation)
return;

// If I remove the next two lines, the character has wrong rotation values for its bones, missing parts, and also does not swap images in the proper frames.
// If I keep the next two lines, the character does not have ANY transition between states at all, the animations are all super stiff
skeletonanim.skeleton.SetToSetupPose();
skeletonanim.state.ClearTracks();

if (name == "idle_315_bottom_left") {

skeletonanim.state.SetAnimation(0,"idle_315_bottom_left", true);
return;
};

skeletonanim.state.SetAnimation(0, name, true);
currentAnimation = name;

}
Thanks for your help :bang: :bang: :bang: :bang:

-- 11 Oct 2015, 15:12 --

Additional information:

1) I am using Spine Pro, Unity 5.2, and the Spine Unity runtimes authored on 3rd of August

2) This is the first and last frame of my walk animation:


3) This is my first and last frame of my idle animation:


4) This is my T-pose:


5) This is what happens if I use SetToSetupPose just before setAnim:
(Problem: no transitions-crossfadings, and the character "walks on the spot" and then immediately switches to idle, instead of transitioning to idle)




6) This is what happens if I do not use the above mentioned lines of code:
(Problem: unable to transition to "full" Idle pose, as bones movement are relative)
(The OnGui button sets the Idle animation)


I need to have crossfading and reset of position of the bones. How can I achieve this?
Kullanıcı avatarı
ciaps
  • Mesajlar: 21

Pharan

To make crossfading work, all the items that have keys in the "from" Animation also need to have keys in the "to" animation. And vice versa.
There's no simple way to make Reset work for crossfading cases.
Kullanıcı avatarı
Pharan
  • Mesajlar: 5366

ciaps

Hi Pharan, thanks: keying every RTS value for each bone gave me the intended result.

I still have some unexpected rotation settings, but I hope I will sort it out myself. Thanks again !
Kullanıcı avatarı
ciaps
  • Mesajlar: 21

Pharan

Glad to hear it worked!

The logic behind this is Spine uses values of 2 keys to interpolate during the built-in crossfading/mixing.
It takes the from key and a percentage weight, and the to key and a percentage weight, and then applies that to make a pose.
When one of the keys is missing, it doesn't make any assumptions as to what the missing key value should be.
Kullanıcı avatarı
Pharan
  • Mesajlar: 5366


Dön Unity