Click here to Skip to main content
13,201,763 members (71,054 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


7 bookmarked
Posted 3 Jan 2014

Unity: Animate Your Character Using Mecanim

, 3 Jan 2014
Rate this:
Please Sign up or sign in to vote.
Unity: Animate your character using Mecanim

In the Legacy animation system (before unity 4.0), we used to manually write code to control the animation. We were either using an animation.CrossFade(); or animation.Play(). After the advent of unity 4.0, things changed adversely. Unity introduced something called MECANIM.

Mecanim, Unity’s uniquely powerful and flexible animation system, brings your human and non-human characters to life with incredibly natural and fluid motion.


This is a simple mecanim setup (animator window), which I used in my soccer game to control the character.

The animated character is controlled by changing the state, state is managed through the parameters (speed and direction) which you will define in your script (C#/JavaScript/Boo).

The transition (white arrow in the figure above) from Idle to walkback and vice-versa is controlled by playing with speed parameter.

  • If speed is less than -0.1, then transition from idle to walkback (down arrow)
  • If speed is greater than -0.1, then transition from walkback to idle

In my soccer game, the character will be in ‘Any state‘, when I start increasing speed (forward arrow), character will change the state from ‘idle’->’walk’->’Run’.

As you see, there is one more parameter called ‘Direction’. Let me tell you how I use this to control (change state) my character.


In mecanim, the most important concept to understand is ‘Blend Tree’.

Blend Trees are used for allowing multiple animations to be blended smoothly by incorporating parts of them all to varying degrees.

Using the blending parameter Direction, I make the character turn right or left in the current motion (walk or run). For any blending parameter, the minimum value is -1 and maximum value is 1. So when my direction parameter value is:

  • -1, character will turn left in current motion
  • 0, straight in current motion
  • 1, will turn right in current motion


Check the threshold value to understand what I was talking about.

In a summary:

Unity has a rich and sophisticated animation system called Mecanim. Mecanim provides:

  • Easy workflow and setup of animations on humanoid characters.
  • Animation retargeting – the ability to apply animations from one character model onto another.
  • Simplified workflow for aligning animation clips.
  • Convenient preview of animation clips, transitions and interactions between them. This allows animators to work more independently of programmers, prototype and preview their animations before gameplay code is hooked in.
  • Management of complex interactions between animations with a visual programming tool.
  • Animating different body parts with different logic.

For a complete experience of mecanim, please go through this video.

Courtesy :Unity3D

Filed under: unity

Tagged: Animate your character using Mecanim, Animation, Animator, Mecanim, Unity


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171020.1 | Last Updated 3 Jan 2014
Article Copyright 2014 by Vidyasagar Machupalli
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid