[Video][Unity StateMachine Tutorial 2] Animation/Character Handling

Part I:


So for this one tutorial , we’re going to be making a few animations for a character. This is the spritesheet we’re going to use:





Yes! It’s Cress, from Tales of Phantasia. Not my art and the link to the original guys who made it is there for you to see. I edited the green background and just kept the sprites.

What we did in the first video was:

  1. Create an Empty GameObject which is our character, it just doesn’t know it yet. Rename this to MainCharacter.
  2. Add a Sprite Renderer to that gameobject and make one of the sprites (any you want) the base “idle” sprite. This won’t matter, since code will be changing our sprites constantly.
  3. Go to the Window menu on top and make sure you have both an Animation and an Animator window somewhere. I put them next to my Console since that’s where I’m used to seeing it.
  4. Click Create for your object to be able to be animated and now create a new animation in a new folder called “Animation”, call it “Idle”.
  5. Create this animation with 2 frames. It’s fine as is.
  6. Create animations for Walk, Run, Attack, Jump, Fall and Die.

After you’re done with these first steps, you’re ready to jump on the coding side of the tutorial. For this part we’re going to:


  • Make our Camera follow our Character
  • Make our Character move around and with this,
  • Create a StateMachine that allows seamless animation switching when states change.


Click on our MainCharacter and on the Animator, create a new Parameter called “State”. This state will be given by code and let the character know what he’s actually doing. Now, we must makeĀ each state Transition to and from each other and decide which state ID each one will have. For this tutorial’s sake, our IDs will be:


  • Idle = 0
  • Walk = 1
  • Run = 2
  • Jump = 3
  • Fall = 4
  • Attack = 5
  • Death = 6

Part II:



Now we must create simple movement/ground detection/jumping for our character and create the StateMachine. Steps for this:

  1. Create a GroundChecker Object.
  2. Create Ground and add Ground as a layer to it.
  3. Add Box Collider 2D to both the Character and the ground.
  4. Add a Rigidbody2D to the character.
  5. In code, find the Animator, Rigidbody2D and GroundChecker
  6. On FixedUpdate, create a grounded function to check if the character is grounded. This will be achieved through Physics2D.OverlapCircle with center on GroundChecker
  7. Choose a key for each and do checks for grounded jump, attack, run and walk.
  8. Create the State Machine with all the states.
  9. In each state, assign the State variable to the Animator through “Animator.SetInteger(IntName, value)”
  10. Follow good logic! The video shows one way to do it but feel free to design your own.


If you have any questions, I’m around. Thanks for reading!


Leave a Reply

Your email address will not be published. Required fields are marked *