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:
Loading Image
3) This is my first and last frame of my idle animation:
Loading Image
4) This is my T-pose:
Loading Image
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)
Loading Image
Loading Image
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)
Loading Image
I need to have crossfading and reset of position of the bones. How can I achieve this?