Making a Unity Sprite-based Character (for 2D)

Note: This tutorial is for sprite-based Characters that appear in "Unity 2D" games, as explained here. To create sprite-based Characters for 3D games, see here.

This tutorial makes use of the 2D Brain sprites that Adventure Creator comes with (found in AdventureCreator -> Demo2D -> Graphics -> Sprites -> Brain), but the steps involved work for any set of sprite animations.

Regardless of whether you are making a Player or NPC, begin by dragging your base sprite into an empty scene. Here, we've used Brain's Idle_D sprite. Whichever sprites you use, be sure to have set their Pivot to Bottom, in it's Import Settings.

Rename the object to something sensible, like CharacterSprite. Reset it's Transform values to place it at the centre of the scene, and place it on the Ignore Raycast layer. Then add the two components Animator and FollowSortingMap. Inside the FollowSortingMap Inspector, check the Follow Sorting map? checkbox.

Now we need to create our animation clips. When dealing with 2D characters, Adventure Creator looks for clips that end with a directional letter to mark work out which direction the character should be facing. For example, Walk_D is the "Down" walk animation, while Walk_L is the "Left" walk animation. If we have diagonal sprites, we can use those as well - Walk_UL is the "Upper Left" walk animation.

To keep things simple, let's just deal with a character that can stand still and walk in the four main directions. With our sprite sequences ready, open up the Animation window and dock it - it can be accessed from the top toolbar under Window -> Animation.

Even if an Idle animation is only one sprite long, it must still be made into an animation clip. Make your scene sprite the active object, then drag your character's "Idle down" sprite into the Animation window. You'll be presented with a Create new animation pop-up window. Give it the name Idle_D and save it.

The single sprite now appears in our Animation window.

We can now create new clips by clicking on the clip's name and choosing Create new clip. This time, save a clip called Idle_L, and drag your "Idle left" sprite into the Animation window. Repeat this for your "idle right" and "idle up" sprites, naming the clips Idle_R and Idle_U respectively.

The process for making our walk clips is similar, only this time we'll be making clips that feature more than one frame. To do this, simply select all the sprite frames in your animation at once when dragging them into the Animation window.

You may need to adjust the frame rate of your animation - you can do so with the Samples setting.

You should end up with eight animation clips named as follows:

We'll need to build an Animator Controller to drive the sprite's animations. Create one one in the Project window by choosing Create -> Animator Controller in the toolbar.

Then assign it to your sprite by dragging it onto your character sprite's Controller field in the Inspector.

We now assign our animation clips to the Animator. Open the Animator window and dock it - it's found in Window -> Animator in the top menu. If they aren't already in there, drag in all eight animation clips into the Animator window. You need not worry about Transitions or Parameters.

With our Controller complete, we now need to create a parent GameObject to contain the sprite. Create an Empty GameObject from the top toolbar, under GameObject -> Create Empty.

Reset this Empty's Transform values to place it at the centre of the scene, and rename the object to something sensible (here, Character). Make the sprite a child of this object by dragging the sprite onto this Empty.

Now we'll add the necessary components to our character. Add the following components to the Empty:

  • Circle Collider 2D
  • Rigidbody 2D
  • Player / NPC script (either one)
  • Paths script
  • Audio Source (optional)

The Circle Collider 2D should be positioned at the Character's feet.

At the top of the Player or NPC Inspector, set the Animation engine to Sprites Unity. The rest of the Inspector will change to reflect this.

Just beneath the Animation engine field is the Standard 2D animations panel. First, set the Sprite child field as the sprite child object in our scene. Then enter in the clip names of our Idle and Walk animations (without the underscore and directional character). We can leave the Run and Talk names blank, but make sure Diagonal sprites remains unchecked.

Check the Ignore gravity field as well, found in the Rigidybody settings.

The character is now ready to be placed in our Adventure Creator game! Finish up by turning them into a prefab. If you are making a Player character, be sure to place the prefab in a Resources folder, tag it as Player, put it on the Ignore Raycast layer, and assign it in the Settings Manager.

Adventure Creator and this website are copyright Chris Burton, ICEBOX Studios

Go to top
Do NOT follow this link or you will be banned from the site!