Step-by-Step Guide: Stick-Figure Animation in Blender and Unity

I am writing this post more for my own reference. I wanted to created a character in Blender, rig and animate it and then use it in Unity. Following videos show how I did this. I created a simple, stick-figure like, character in Blender and used it in Unity. In Unity I used Character controller, new input system and animation controller to move the character.

Stick-Figure Modelling in Blender

I started with an empty project (other than the default cube) in Blender and created a stick-figure character. I collapsed all the vertices of the cube to a single vertex, applied mirror modifier, skin modifier and subdivision surface modifier. Then extruded different parts of the character.

Rigging

I then rigged the character using Rigify add-on. This add-on is built-into Blender, but not enabled. You need to go to add-on preferences and enable it. Rigify makes applying basic human rig quite easy.

Animation

I wanted two animations for the stick-figure – 1. walking and 2. idle. Though the idle animation I have created has no motion. I could have added breathing animation, but I wanted to keep the video short. The walk animation I have attempted is far from perfect, but the video shows the basic process of creating animation using the rig.

Export Character & Animation

In this step I export the model and associated animation as a FBX file.

Import Stick-Figure Character in Unity

Importing FBX file in Unity is as easy as dragging and dropping the file in Assets folder. I also add material to the model in this step. Then I add the character in the scene.

Add Terrain

In this step I add terrain object in the scene. The character will navigate on this terrain. I also apply terrain material.

Add Character Controller

I have used CharacterController component of Unity for movement of the stick-figure character. This component takes care of movement up/down steps/slopes too.

Add Cinemachine & New Input System

I have used Cinemachine virtual camera to follow the character. And I have used Unity’s new input system for controlling the player movement. Both these features needs to be installed in Unity using the package manager.

Add On-Screen Joystick

In this step I add an on-screen joystick to control the player/character movement. This is in additional to controlling movement using keyboard, as explained in the previous step. To add the (simulated) joystick, I add a circle image on the canvas and then add On Screen Stick component to the image. Then set it’s behavior to Joytstick.

Modify Terrain

The terrain we added is completely flat, In this step I added a few bumps using Set Height tool of Terrain. This will also show how character controller we added earlier works on uneven surface.

Add Input Actions

The new input systems of Unity allows one action to map to different devices, like keyboard, gamepad joystick etc. I create a Walk action and map it to keyboard and joystick in this step.

Implement Script to Move Character

I add a script to implement player movement in this step. The script checks is any action is performed, using the reference to PlayerInput object and move or turn the player. It also sets appropriate walk/idle animation using AnimatorController.

Add Animator

When the character is moving, we want to apply walk animation to it. When stopped, we want to apply idle animation. I also want to have different animations when user is moving – walk, walk fast and run depending on the input. When using the keyboard, there are only two states for up key – i.e. pressed or not pressed. However the on-screen joystick has many in-between input values. So, I used Bind Tree in the Animator to apply the same walk cycle at different speed (for walk, walk fast and run) for different value of “speed” parameter, which is set from the script. Of course, instead of reusing the walk animation, you can create separate animations (in Blender) for walk fast and run.

Apply Gravity to Character

After the character moves over bumps, the character does not move back to ground and keeps floating. To fix this we simulate gravity in the script. If the character is not on the ground then we need to apply velocity towards the ground till the character is on the ground.

Key Combinations for Run Action

In this step I show how to use key combinations in the Input System to make the character walk or run using the keyboard. We saw above that with on-screen joystick, it is possible by controlling the distance we move the circle. But the way we have configured actions currently, up key on the keyboard can either start the walk or set the character idle. This video shows how we can use combination of Shift+Up arrow key to make the character run.

Conclusion

I have tied to create my own character in Blender and use it in Unity, as shown in the series of videos above. Even though the animation is far from perfect, I wanted to try out creation of a human like model, rigging and adding different animations to it in Blender. Then I showed how this character can be used in Unity to navigate in the scene using Character Controller, new Input System and Animator. Instead of creating you own model, you can import any model (with walk animation) , from example from Mixamo, and use it in Unity using the same methods shown in the above videos.

-Ram Kulkarni

Leave a Reply

Social