Click here to Skip to main content
Click here to Skip to main content

Unity : Animate your character using Mecanim

, 3 Jan 2014
Rate this:
Please Sign up or sign in to vote.
In the Legacy animation system(Before unity 4.0),we used to manually write code to control the animation.We were either using a animation.CrossFade(); or animation.Play().After the advent of unity 4.0 ,things changed adversely.Unity introduced something called MECANIM. Mecanim, Unity’s uniquely powe

In the Legacy animation system(Before unity 4.0),we used to manually write code to control the animation.We were either using a 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.

Mecanim

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-a-versa is controlled by playing with speed parameter.

  • If speed less than -0.1,then transition from idle to walkback (down arrow)
  • If speed 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.

mecanim2

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 to 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.

mecanim3

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.

<iframe class='youtube-player' type='text/html' width='800' height='480' src='http://www.youtube.com/embed/Xx21y9eJq1U?version=3&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1&wmode=transparent' frameborder='0'></iframe>

Courtesy :Unity3D


Filed under: unity Tagged: Animate your character using Mecanim, Animation, Animator, Mecanim, Unity

License

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

About the Author

Vidyasagar MSC
Software Developer (Senior)
India India
Microsoft MVP (Games for Windows)
Developer | Blogger | Mentor | Gamer
Coder by profession | Gamer By Heart
Technical Blog : http://onestopdotnet.wordpress.com/
About me: http://about.me/mscvidyasagar
Follow on   Twitter

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140718.1 | Last Updated 3 Jan 2014
Article Copyright 2014 by Vidyasagar MSC
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid