Fooprint

I'm switvhing from SmoothMoves2D (which use Unity3D animation) to Spine but I really can't understand how to CrossFade animation and the lack of Documentation is not helping me.
I'm playing with the spineboy character.
Here's a simple code
if(Input.GetAxis("Horizontal") > 0.1f){
skeletonAnimation.state.SetAnimation(0, "walk", true);
}
if(Input.GetKeyUp(KeyCode.Space)){
skeletonAnimation.state.SetAnimation(0, "jump", false);
}
Fooprint
  • Сообщения: 4

Pharan

Crossfading duration values are stored/set in the SkeletonData asset through the inspector (the same thing you assign the .json and atlas to). There's an "Add Mix" button.

The SkeletonAnimation's AnimationState code automatically reads from SkeletonData to crossfade between pairs of animations (pairs you specify) whenever the animation changes via SetAnimation or some other ways.
Аватара пользователя
Pharan
  • Сообщения: 5366

Fooprint

I understand that but i want to know why if I press the right arrow button only the first frame of my animation is played and if I press space while right arrow is pressed nothing happen.

EDIT: what I want to achieve is to press the "right button" to make my player run and then while he's running make it jump pressing "space"
Fooprint
  • Сообщения: 4

Pharan

I think you want a keydown/buttondown condition and not just getaxis.

This isn't really a Spine problem. Your code just keeps setting the animation which causes it to keep going back to the start of the animation.

Keep at it. Making a character control input system and character animation system (on top of Spine's basic layer, or any other system) takes some work.
Аватара пользователя
Pharan
  • Сообщения: 5366

Nate

Aye, you're calling SetAnimation every frame that right is pressed.
Аватара пользователя
Nate

Nate
  • Сообщения: 9766

Fooprint

We already have our script for our character I'm just trying to figure our how to does Spine animation works because they looks far different from Unity3D animations.
I managed to make my character jump while he's walking and to detect an idle state but I I can't make it walk again after a jump.
void Update(){
if(Input.GetAxis("Horizontal") > 0.1f){
isRunning = true;
dir = 1;
}
if(Input.GetAxis("Horizontal") < -0.1f){
isRunning = true;
dir = -1;
}
if(Input.GetAxis("Horizontal") == 0.0f){
isRunning = false;
}

if(isRunning && anim != "walk" && anim != "jump"){
anim = "walk";
skeletonAnimation.state.SetAnimation(0, anim, true);
gameObject.transform.localScale = new Vector3(dir * 1.0f, 1.0f, 1.0f);
}
if(!isRunning && anim != "drawOrder"){
anim = "drawOrder";
skeletonAnimation.state.SetAnimation(0, anim, false);
}

if(Input.GetKeyUp(KeyCode.Space) && anim != "jump"){
anim = "jump";
skeletonAnimation.state.AddAnimation(0, anim, false, 0);
}

}
Fooprint
  • Сообщения: 4

Pharan

How experienced are you at programming in C#?
If you read up on events and delegates, or watch the Unity C# intermediate scripting tutorials on that topic on their website, they're a huge help for what you need. skeletonAnimation.state has some really handy events built into it that can let you know when an animation has finished playing.

Or more primitively (but still pretty okay), you have access to what the SkeletonAnimation is currently playing by using skeletonAnimation.state.GetCurrent(0). That returns null when no animation is playing, but if not, returns a TrackEntry you can get the .Animation member of (representing the currently playing Spine.Animation).
Аватара пользователя
Pharan
  • Сообщения: 5366

Fooprint

Pharan писал(а):How experienced are you at programming in C#?
If you read up on events and delegates, or watch the Unity C# intermediate scripting tutorials on that topic on their website, they're a huge help for what you need. skeletonAnimation.state has some really handy events built into it that can let you know when an animation has finished playing.

Or more primitively (but still pretty okay), you have access to what the SkeletonAnimation is currently playing by using skeletonAnimation.state.GetCurrent(0). That returns null when no animation is playing, but if not, returns a TrackEntry you can get the .Animation member of (representing the currently playing Spine.Animation).
I'm pretty good with C# my script is just a simple workaround I wrote while I was playing with Spinde because I haven't found any good script reference. I will take a look at the video.

Thank you
Fooprint
  • Сообщения: 4

Pharan

Oh. In that case, just take a look at the code of the Spine.AnimationState class in AnimationState.cs. You'll find most of the useful things in there, things you can call, things you can poll, and more importantly, the events that you can subscribe to.

If you're bent on this short dirty version, the problem is in the condition for your walk animation. the string anim gets set to "jump" right before you play the jump animation, but nothing will set the string back to anything else after the jump animation has completed. So the condition anim != "jump" will always fail after jumping.
Аватара пользователя
Pharan
  • Сообщения: 5366


Вернуться в Runtimes