Unity Game Development – 04 – Player Animation

Platformer games usually have lot of characters on them. The Hero, the enemies, some NPCs etc. IN order to really use a character, we need to have the appropriate animations on it . Let’s take Player movement as an example. If the player is not used, it should be in idle animation, the player should be able to run , jump , dive, fight …etc.

In this post, we will take an existing chaacter, and see how we can add animations to the character in unity.

1.Importing Spritesheets and splitting sprites

Characters usually come in Spritesheets. And since there are a lot of open source spritesheets on the internet, i just happened to get my hands on one..

As you can see , We have a spritesheet with different player movements available.

We can use the SpriteEditor and slice this up into the component Sprites. It should now appear like this with the individual sprites …

2. Creating Animations.

Select the first 3 sprites and drag that on to the Scene. A window will popup , asking to create a new Animation. Name it appropriately and save.

You will see a Controller and an Animation created. The controller is shown below. It contains several states, and since it is a new one, it contains current “Idle” state as well as the default Entry, Exit and AnyState

The Animation looks like below.. For the selected “Sprite” , it shows the 3 frames that were selected, and also shows the frame rate per second this animation plays. We can tweak with these settings through the editor. Each of the three frames is a keyframe . We can drag other sprites on to the empty states to make various animations.

3. Creating Other Animations

We can create states for the other movements and add Animations to those.

I have created a new Empty State called “Run” . We can add transitions between 2 states. It will create directional arrows that connect states.

After adding transitions, we can even control when the transitions should occur.

4. Transitioning between States

We can create some parameters to control the transitions, for example an integer flag that controls whether the state should be run or idle.
In the below step, upon selecting the transition, we can see the properties of the transition on the right. Once the parameters are created, they can be added in the Conditons section in the Inspector.

This is how the final demo player Animation controller looks like …

The below is an example of how the player’s state changes . Currently it shows the player running motion.

In the next post, we will see how to use these Animations in the Game