Search Unity

Turn your character into a player!

April 14, 2014 in Technology | 8 min. read
Topics covered

This blog post will run you through the steps to import, animate and control your character as a player in Unity. It is designed to be 3D package agnostic, so whether you use Max, Maya, Blender or any of the many supported modelling programs, you should find what you need to turn your character model into a player in a Unity scene. The sample assets will provide all the animations needed for controlling the character, but of course you can add you own. In this example I've created a Lola3000 character inspired by Barberella, Soroyama & Metropolis amongst other influences and brought her to life, running through a tricky landscape of floating islands high above a sci-fi cityscape.


Follow the 12 Steps

We'll begin with steps you can use to prepare and rig your character, before adding BlendShapes, verifying and then importing your rigged file into Unity. We'll then set up some of the materials and shaders so that you can get your character looking it's best. Next we will be creating an avatar to match your character rig and set it up for animation using a 3rd person controller with the Unity sample assets. We'll load in a custom animation and setup a blendshape layer to further customise the character. Finally we'll add lights and fx to the environment and camera to finish the look.


1 Preparing your Model Unity is a real-time platform, so prepare your model to look good without breaking the bank polygon wise. Name your materials and textures sensibly and use normal maps for extra detail, there are no polygon limits but the more you use, the less you have to spend on environment, FX and other characters. 5-25,000 can be a good range to aim for, depending on platform - so reduce polygons with the tools in your 3D package where necessary. Place your textures in a folder called textures within your Unity project assets folder and re-path them before you export.


2 Rigging your character This stage will depend on your 3D package, skills and time available. Once your model is prepared in a t-pose you can either create a bone hierarchy from scratch - assigning skin weights - use your 3D package in-built tools to generate and skin to a skeleton, or use a fully automated solution like Mixamo Autorigger. In Maya for example, use Human IK, 3DSMax has Biped/CAT along with the skin modifier and Blender provides Rigify, as a few examples to create your skeleton hierarchy and assist with skinning. See Mecanim> preparing your own character in the documentation for more details.


3 Set up BlendShapes Unity supports BlendShapes (Morph targets) so decide which part of the character requires morphing, and set up in your package appropriately, using BlendShapes in Maya, Morpher in 3DS Max and Shape Keys in Blender for example. This is often used for phoneme shapes when animating a talking face and works by assigning morphed shapes of the same number of vertices (often a duplicate of the original) to a target so that you can blend between versions to obtain different shapes without animating a complex bone hierarchy.


4 Verify and export This stage is important to minimize errors and troubleshooting when you set up your model later. Remove unused meshes and extraneous assets like lights or cameras from your scene, or simply use the export selected if you 3D package allows. Use the FBX file format if you can, to allow for file portability and simplicity - if you have your own animation clips be sure to check the animation check box in the export dialogue. Re-importing your exported model into the 3D package is often a good way to verify your model before bringing it into Unity.


5 Importing your model You can drag your FBX into the Project pane, or if you exported here already your model will be picked up automatically. You can select your model in the project browser and set up the options in the inspector panel. You should probably leave most of these as default, but check the Scale Factor, as scale can vary hugely depending on units used in your 3D package and your export settings. Click apply and drag the model into the Scene. You can create a (1m) cube to make sure the scale is correct and readjust.


6 Setting up your materials in Unity Select your character in the scene and observe the associated material(s) in the inspector, these should have been created in materials folder where your model is exported. Each material has a drop down for shader, choose one appropriately e.g. Bumped Specular, so that you can define a base colour (tint) specular colour and the texture maps for the diffuse (Base RGB), gloss in the alpha channel and a normal map to add surface detail. Reflective materials can also have a cubemap assigned for reflections, which you can render once in the Unity editor or realtime (pro) for dynamic reflections.


7 Creating an avatar Once imported your character model needs to have an avatar applied, this will map your skeleton to an avatar to use with any humanoid animation. Select the character model FBX file in your Project pane. Select the Rig tab and choose Humanoid for 'Animation Type' – click configure to create and configure. If your rig is good to go it will all be in green, otherwise assign bones to the correct slots or revisit your bone hierarchy and re-export to closer match the avatar. You can test your skinning in the Muscles tab by dragging the sliders. Click Done when finished.


8 Adding a controller Unity sample assets provide all you need to control your player. From the project window, drag the Third Person Character prefab from the Sample Assets\Characters and vehicles\Third person Controller\prefabs folder into your scene. In your Hierarchy delete the Ethan node underneath Third Person Character. Drag your character node on top of your Third Person Character node which has all scripts,  parameters and the player tag already assigned. From the Cameras\Prefabs folder drag the Free Look camera rig into the scene, add and position a 'plane' game object and press Play!


9 Adding your animation If you have imported or acquired animation from the store, you can replace the animations from the character animator. Select your character root node, Open the animator from the Window menu - This opens a pane that manages which state your character is in and therefore which animation to play. Double click Grounded state to open a blend tree for when you character is on the ground. Select the blend tree and over in the inspector click the little circle next to an animation to choose another. Press play to preview then stop and make adjustments as necessary.


10 Adding BlendShapes and tweaking your character Create an animation in your source package which blends between two or more meshes, as outlined in step 3. Re-export your mesh and include animation > morphs in the FBX dialogue. In Unity create a new layer in your animator window set blending to additive and weight: 1, then drag in your clip from the project window, create an empty state and right click > Make transition – and transition to and from the clip. Set a condition for this e.g. forward: greater than 0.5 for to - and forward: Less than 0.5 for from transition in the inspector.


11 Adding environment, lights and settings To immerse yourself in the game you can planes & primitives to create a greybox test environment to play about in, or use levels from the sample assets or asset store and of course import your own environment artwork. Any imported artwork needs to have 'Generate Colliders' checked and applied in the inspector, for the imported file in the project view, so that you can walk on the surface etc. Create a 'directional light' from the Create button at the top of the hierarchy and adjust the parameters in the inspector.


12 Adding Post FX and polish Unity pro includes a number of full screen Image FX that can help improve the look of your scene. Separate the 'Game' view by dragging the tab out to preview. Select the 'Main Camera' node under the Free Look Camera Rig. In the inspector click Add Component > Image Effects > Camera > Depth of field - for example - to retain focus on your character, but blurring the background akin to a wide aperture. You can add as many others as your eyes and frame rate can handle so try vignette, bloom, ambient occlusion, so go ahead & play!

Here are some Useful resources to continue with your project:

To follow the video tutorial click Play >


April 14, 2014 in Technology | 8 min. read
Topics covered