Making a Mecanim-based Character

This tutorial is focused on taking a Mecanim-ready character model and integrating them into Adventure Creator. For more information about working with Unity's Animator (Mecanim) system, see here.

This tutorial makes use of the KBH Toon - Adventure 01 animated character on the Unity Asset Store, but the steps involved work for any Mecanim-ready character model.

Regardless of whether you are making a Player or NPC, begin by dragging your character model into an empty scene.

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

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

If your character makes uses of root motion, Adventure Creator will support this - just check Apply Root Motion as usual.

Let's lay down some animations. Open the Animator window and dock it - it's found in Window -> Animator in the top menu. Drag in four animations for Idle, Walk, Run and Talk, making the Idle our default. Here, the SuperIdle2 animation will act as our Talk:

Define two Parameters: a Float called MoveSpeed, and a Bool called IsTalking. Leave them at their default values.

We'll use the MoveSpeed float to determine which of out the Idle, Walk and Run animations to play, but we want to keep our character still if the float is very small. Between the Idle and Walk animations, create two Transitions (right click on one, and choose the other, to make a Transition).

For the Idle -> Walk Transition, set the Condition to MoveSpeed Greater 0.1.

For the Walk -> Idle Transition, set the Condition to MoveSpeed Less 0.1

Similarly, create two more Transitions between Walk and Run. For the Walk -> Run Transition, set the Condition to MoveSpeed Greater 1.

And for the Run -> Walk Transition, set the Condition to MoveSpeed Less 1.

Finally, create two Transitions between Idle and Talk. For the Idle -> Talk Transition, set the Condition to IsTalking true.

And for the Talk -> Idle Transition, set the Condition to IsTalking false.

Your completed Controller should look like this:

Now we'll add the necessary components to our character, and then tell Adventure Creator how it can control our defined Parameters. Add the following components to the model:

  • Capsule Collider
  • Rigidbody
  • Player / NPC script (either one)
  • Paths script
  • Audio Source (optional)

The Capsule Collider should be adjusted such that it's bottom touches the floor.

Then check all three boxes in the Rigidbody's "Freeze Rotation" field.

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

Just beneath the Animation engine field is the Mecanim parameters panel. Here we define the names of our Controller's Paramaters. Set the Move speed float as MoveSpeed, and the Talk bool as IsTalking.

If we wanted, we could also supply a Turn float Parameter to integrate into the Controller. This float becomes -1 when the character turns left, and +1 when the character turns right. You can also tell Adventure Creator to rely on Mecanim's Root Motion feature to move the character - otherwise, it will be moved using the Rigidbody.

Down in the Movement settings panel, we can define what values the MoveSpeed float will take when the Character moves. In our Controller, the Walk animation plays when the float is greater than 0.1, but when it's greater than 1 the Run will play instead, so set the Walk speed scale to 1, and the Run speed scale to 2.

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!