How to Create, Rig and Animate a 3D Character for Unity

In this section, we will go through some very simple steps to create the character that you will be using in Unity, including:

  • Using Mixamo, a free online software, to select a character for your game.
  • Animating your character in Mixamo.
  • Exporting your animated character so that it can be used in Unity.

So, after completing this chapter, you will be able to:

  • Select your own 3D character.
  • Select and apply different types of animations to your character.
  • Export your character and the associated animations so these can be used in Unity for your game.

Creating your character

For this part of the book, we will have a look at Mixamo which is an online software that makes it possible to create and animate 3D characters. The idea, when using this software is to create and animate your characters, and then to import them so that they can be used in Unity.

If for some reason, you would prefer not to use Mixamo, the animated characters used in this chapter are available in your resource pack that you can download by following the instructions included in the section entitled “Support and Resources for this Book”.

  • Please open the following page in your browser:
  • Once the page is open, you can click on the button labelled Login, if you already have an account for this site.
  • You can also click on the button Sign-up for FREE, to create an account otherwise.

Figure 1‑1: Opening the site

  • If you chose to create an account, the following window should appear:

Figure 1‑2: Signing-up to Mixamo

After signing-up, and completing all the necessary steps, you should now be able to login.

  • As soon as you are logged-in, you will have the choice to select your own character and animation.

Figure 1‑3: Starting Mixamo

  • To start with, we will select a new character; to do so, please press the tab called Character located in the top-left part of the window.
  • Once this is done, a list of characters that you can use for your games will be displayed; these characters are already textured and rigged which means that they include a skeleton that makes it possible for them to be animated later.

For this example, but again you can choose any character if you wish, we will select the character dreyar, by clicking on the corresponding image on the left hand side of the screen, as per the next figure.

Figure 1‑4: Selecting your character

  • If a window asking you to “go ahead although the previous character will not be saved” appears, please press the button labelled “Use this character“, as per the next figure

Figure 1‑5: Confirming your character selection

Once this is done, you will be able to see the character that you have selected in the right-hand side of the screen, in what is often called a T pose (often called the reference pose), as per the next figure, which means that the character is not yet animated.

Figure 1‑6: The character in the T pose

Animating your character

So at this stage you have selected a character, and the next step is to be able to add some animations to the character.

  • Please click on the tab called Animation, located in the top-left corner of the window.
  • You should now see a list of animations made available to you by Mixamo.

Figure 1‑7: Selecting animations

Note that the character that you see on the animation is not the final animated character, but just a representation of how the animation that you are about to apply to your character would look like.

To look for specific types of animation, you can use the menu located in the top-left corner of the window, as per the next figure.

Figure 1‑8: Filtering through the animations

This menu makes it possible to filter through the animations by genre (e.g., Combat, Adventure, Sport, etc.)

You can also, if need be, perform a search, by using the search window available in the top left corner of the window. In our case, because we will be looking for a walking animation, we can type the text walking in the search field.

Figure 1‑9: Searching for an animation

After pressing Enter on your keyboard, Maximo will display a list of animations for which the name includes the word walking.

Figure 1‑10: Displaying the results of the search

In our case, we will select the very first animation called walking (the first animation in the top left corner), by clicking on this animation.

After a few seconds, you should see that you character located in the right part of the window is animated, using the animation that you have just picked as per the next figure.

Figure 1‑11: Applying an animation to our character

As you will see, the character is animated, however, it doesn’t stay on the spot, and it is difficult to see the full animation. To remedy this problem, you can tick the box for the option called “In place“, located in the right part of the window.

Figure 1‑12: Using the “In Place” option

In fact, for your game, you only need this animated character to walk on the spot, as the overall movement (i.e., going left, right, forward and back) will be managed through Unity. Also note that you can modify some of the other parameters if you wish (e.g., speed, overdrive, etc.)

Once this animation has been applied, we can now save it.

  • Please lick on the button labelled Download.
  • In the new window, select the format FBX for Unity (.fbx) and leave all the other options as default, and then click on the button Download.

Figure 1‑13: Setting the download options

  • The browser will ask you where you would like to download this file (dreyar_m_aure@Walking.fbx).
  • Please save the file to a location of your choice.

Importing your character

So at this stage you have saved your animation, and we will now import it in Unity.

  • Please open Unity, if this is not already done.
  • Create a new project in Unity.
  • In the new scene, please make sure that the Project window is visible.
  • Return to your file system where the animation was saved. In my case, the animation was called dreyar_m_aure@walking.fbx.
  • Drag and drop the file dreyar_m_aure@walking.fbx from your file system to the Project window in Unity, as illustrated in the next figure.

Figure 1‑14: Importing the animation

Once this is done, this should create a file called dreyar_aure@walking.fbx, a folder called dreyar_m_aure@walking.fbm, along with another folder called Materials in the Project window.

Figure 1‑15: The folders created after the import

Now that we have imported our character and its dependencies, we can start to create a ground on which this character will walk.

  • Please create a new box: select GameObject | 3D Object | Cube.
  • Set its x and z scale attributes to 100.

Next, we will create another cube that will be used to assess (and to subsequently readjust) the size of our character. This is because the scale factor used when creating this object might not match our project.

  • Please create a new cube: select GameObject | 3D Object | Cube.
  • You can then move this cube just above the ground. By default, this cube will be 1 meter wide.

Figure 1‑16: Adding a cube to gauge the size of the 3D model

Once this is done, we can add our imported 3D character to the scene near the cube, to check if its original scaling is correct.

As you will probably see, this character, when added to the scene, is approximately 10 times bigger that the small box; this means that we will need to rescale the character accordingly and divide its size by 10 (or multiply by .01).

Figure 1‑17: Adding the character to the scene

So let’s proceed with the rescaling:

  • Please click once on the object called dreyar_m_aure.fbx from the Project window.
  • Check that the Inspector window is open.
  • In the Inspector window, click on the tab called Model.
  • In this tab, enter the value 0.1 for the attribute called scale and then press on the button labeled Apply located in the bottom-right corner of the Inspector window, as per the next figure.

Figure 1‑18: Rescaling the character

After clicking on the Apply button, you should see that the character has been rescaled and that its size is now more realistic (about 1.8 m), as per the next figure.

Figure 1‑19: The character after changing the scale

Once this is done, you can play your scene, and you should see that the character is immobile.

Figure 1‑20: The character is immobile

The reason for the absence of animation is that this character in order to be animated, needs to be added a component that is called an Animator Controller; this component will be in charge of deciding what animation should be played for a specific 3D character and when.

  • First, please click on the object called dreyar_m_aure@walking in the Hierarchy window.
  • We could rename it NPC, for now.
  • Then look at the Inspector window.
  • You should see that this object has a component called Animator; however, its attribute called Controller is empty, as illustrated in the next figure.

Figure 1‑21: Displaying the Animator Component

So, we need an Animator Controller to be able to animate our character and we will create one accordingly.

  • In the Project window, select: Create | Animator Controller.
  • A new Animator Controller will be created; you can rename it ControlNPC, for example.

Figure 1‑22: Renaming the Animator Controller

Once this is done, we can apply this Animator Controller to our 3D character:

  • Please select the object NPC in the Hierarchy.
  • Drag and drop the Animator Controller called controlNPC from the Project window to the attribute Controller for the component Animator, as per the next figure.

Figure 1‑23: Applying the new controller to the 3D Character

Once this Animator Controller has been created and linked to our character, we need to set it up, so that we can specify that the walking animation should be used for this character.

  • Please double click on the Animator Controller called ControlNPC in the Project window.
  • This will open the Animator window, as per the next figure.

Figure 1‑24: Opening the Animator window

The animator window helps to manage what is often called a Finite State Machine. Put simply, this means that the software, or the game for our purpose, will include several states, but will be in one state and one state only at any given time.

For our purpose, we need to specify the initial state for our character, and the type of animation that will be played in this particular state.

  • Please right-click on the canvas, and then select: Create State | Empty from the contextual menu.

Figure 1‑25: Creating a new state

This will create an empty state, as per the next figure.

Figure 1‑26: The new state has been created

As per the previous figure, you will see an arrow pointing from the state Entry to the state called New State. This means that whenever the game starts (the point of “Entry“), the default and active state will be New State.

  • So we could rename this state: please select the state called New Sate, and using the Inspector, change its name to walking.

Figure 1‑27: Changing the name of the state

If you look closer at the Inspector, you will see a field called Motion, that is empty for now. So a motion is basically an animation. For now, since this field is empty, the character will not be animated in the state called walking; therefore, we need to specify an animation for this state.

  • Please click on the cogwheel to the right of the label Motion in the Inspector.
  • This will open a new window called “Select Motion“.

Figure 1‑28: Selecting an animation

  • In the search window, the only animation available is called Walking; it was imported with the animated character created in Maximo.
  • You can double-click on this animation to select it.
  • You should now see that the state walking has the associated Motion (or animation) called Waking, as per the next figure.

Figure 1‑29: Adding an animation

By the way, you can check the animation that you have imported from Maximo by expanding the object dreaymar_m_aure.fbx in the Project window, as per the next figure.

Figure 1‑30: Displaying the embedded animations

If you play your scene, you should now see that the character is moving, but that its stops after a few seconds; this is because the animation that we have applied to the character was not set up to loop automatically. However, for our game, whenever the NPC is walking, we want his/her animation to be played indefinitely. For this purpose, we will need to modify the attributes of the animation. So let’s proceed:

  • Please rearrange the layout of the window so that the Animator window is displayed beside the Console window, as per the next figure.

Figure 1‑31: Modifying the layout

  • Next, double-click on the state called walking, so that the properties of the animation linked to this state can be displayed in the Inspector window.
  • Once this is done, in the Inspector window, scroll down to the section called Loop Time, and set the attribute Loop Time to true by clicking on the corresponding tick box, as specified in the next figure.

Figure 1‑32: Looping the animation

Once this is done, and to check that the animation will play properly, you can press the play button, that is within the Inspector window (i.e., at the bottom of the window), and it should display the animated character walking on the spot indefinitely.

Figure 1‑33: Checking the attributes of the animation

  • Once you are happy with this change, you can press the button labeled Apply, located in the bottom-right corner of the Inspector.
  • You can now play the scene again, and you should see that the character is now walking indefinitely.

You may notice, in the Animator window, a blue progression bar for the state called walking, as per the next figure.

Figure 1‑34: Displaying the active state

This bar indicates that we are currently in the state called walking.

The only issue at this stage is that, while we can see and focus on our character properly using the Scene view, it may not appear fully in the game view; so we just need to ensure that the current camera is following our character. To do so, we will import a different type of camera that has the ability to follow a specific target. This camera is included in a package that we need to import.

Before you can import teh camera, you will need to import the Standard Assets, and you can follow the insctrutions from this post to do so.

So let’s import and use this camera:

  • Please select Assets | Import Package | Cameras.
  • A new window will appear.

Figure 1‑35: Importing the package Cameras

  • You can press the button labeled Import.
  • This will create a folder called Cameras within the folder Standard Assets.
  • Using the Project window, please navigate to the folder Assets | Standard Assets | Camera | Prefabs.
  • Drag and drop the prefab called MultipurposeCameraRig to the Scene view.
  • This will create a new object in the Hierarchy called MultipurposeCameraRig. As mentioned earlier, this camera is designed to follow a specific target, so we need to specify this target as the 3D character so that the camera can follow our character.
  • Please select the object MultipurposeCameraRig in the Hierarchy.
  • Then drag and drop the 3D character (the object labeled as NPC in the Hierarchy view) to the field called target for the camera.

Figure 1‑36: Setting the target for the camera

  • Once this is done, you can deactivate the previous camera named Main Camera by selecting it in the Hierarchy, and by using the Inspector window and by clicking on the tick box to the right of its name, so that the box is unticked, as per the next figure.

Figure 1‑37: Deactivating the main camera

You can now play the scene and you should see that the new camera is now following the main character.

Related Articles: