• Unity
  • Looking for Help, Spine Unity Coding

Related Discussions
...

Hello I'm very intrigued in learning how to make a 2d game with spine. I've tested out spine mecanim but the transitions I have is not equal to the spine preview editor. So I went with SpineAnimator.

It was a daunting and challenging task.
I'm a novice at programming with little to no experience. I have this issue in my script that I can't get the jump logic right.

I seperated it to have takeoff, midairloop, and landing.Sadly the landing is problematic and does not work exactly.

Iv'e attached my script for anyone who's willing to help me out on this. And much Gratitudes in advance.

I don't see anywhere in your code where "landed" is being set to True. It looks like you are calculating "isGrounded" to see if your character is touching the ground. So if your character is currently in the Jumping state, you can check to see if isGrounded is set to True. If it is, then you can set your state to Landing.

Also, it may not be the best idea to use the "animation.complete" callback to make changes to your character's state. This is how I would set up jumping:

1) Check if the Player presses the jump button, and your character isGrounded == true, and you're in a State where jumping is allowed
2) Switch your state to Jumping. Set your animation to TakeOff, and then queue up the JumpLoop (using AddAnimation() instead of SetAnimation(), and setting it to loop). Only apply these animations once, right when you switch to the Jumping state. Not every frame.
3) While your character is in the Jumping state, check if isGrounded == true. If it is, then switch to the Landing state.
4) While in the Landing state, check if your Landing animation has completed: "skeletonAnimation.AnimationState.Tracks.Items[trackIndex].IsComplete". If it has, then you can switch states back to Idle. This is sort of the same as using the animation.complete callback, but it keeps your code better compartmentalized.

I also suggest looking up State Machines and implementing a basic version of one - its kind of like what you have going on, but doing a bit of research on it will definitely make it less of a headache to implement 🙂

Thanks for helping
I watched lots of StateMachine lectures on YT and although my C# reading and comprehenssion is akin to a toddler I coould say I was enlightened even just for a bit.

So apparently hwever, I decided to get back to spine mecanim because I found out a fix on mecanim's animation transitions not looking right which is as simple as keying the last pose of every animation in spine. until I polish my skill on coding I think Ill go first with Mecanim style because for me it's quite more viewer friendly.

I appreciate for the time and help youve given. thanks !

Thanks @Jamez0r for the help!

@RA31596 Please keep in mind that using SkeletonMecanim with the Mecanim state machine instead of SkeletonAnimation can still benefit from arranging your player game logic code into states. To be able to handle complex behaviour easily, game logic code should contain the high-level game state of your player which then triggers lower-level visualisation changes - your animations. Then every player state will handle only events relevant in the current state (let's say jumping or reloading in state InAir is not possible for example), and transitions only to possible other states. When it collides with the ground it transitions to a Landing state for example. Starting LandingState starts a landing animation. When landing animation is complete it transitions to Standing state, and so on.

It then does not matter whether an animation is started via setting a Mecanim trigger or by calling SkeletonAnimation.SetAnimation() or SkeletonAnimation.AddAnimation(). Perhaps that's a bit too much for now, but just keep this option in mind when your nested if() {} else {} branches are getting more and more complex and ugly and are no longer easy to maintain.