Monday, March 30, 2020

Tutorial: How to Make a 2d Platformer in Unity - Creating Animations

Creating Animations:

Before we get started programming movement, we need to create our character and our animations.  To create a sprite animation in Unity simply select the sprites in the project window and drag them into the scene.  Highlight the idle sprites (adventurer-idle-00, adventurer-idle-01, adventurer-idle-02) from the adventurer character we downloaded in the last post and drag them into the scene to create an Idle animation.

This will create a GameObject with a SpriteRenderer and an Animator.  The Animator an Idle animation that is set as the default state.  If you hit the play button you will see the character looping through the idle animation.  Do the same with running animation sprites (adventurer-run-00, adventurer-run-01, adventurer-run-02, adventurer-run-03, adventurer-run-04, adventurer-run-05) and the jumping animation sprites (adventurer-jump-00, adventurer-jump-01, adventurer-jump-02, adventurer-jump-03) and save the animations with a name you'll remember.

Setting Up The Animator:

Delete all but one of the SpriteRenderers.  Click on the SpriteRenderer in the scene view and make sure it has an Animator and AnimatorController(if not add an Animator component and right in project view>create>Animator Controller).  Then click on Window>Animation>Animator to bring up the Animator window.  You should see the Animator that is attached to the SpriteRenderer.  Delete all the Animator states.  On the left side of the window click on the parameters tab and click on the plus sign to create a new float.  Name the float Moving.  Right click in the Animator window and select Create State>From New Blend Tree.  Click on the Blend Tree and rename it Idle.  Double click on the blend tree to edit it.  In the inspector, make sure that the blend type is set to 1D and that the parameter is set to Moving.  Click on the plus sign and add 2 motion fields.  Then, click on the circle to show the available animations and choose the idle and running animation for the fields.  The idle animation field should have its threshold set to 0 and the running animation field should have its threshold set to 1.


With the animation set up we're ready to move on the next tutorial!  Next we need to create an environment that our the player can move around in.  We will need to slice a sprite sheet and create a tilemap.
Follow this link to the next post.

No comments:

Post a Comment