Thursday 23 May 2013

Mecanim Animation

When you want to blend the character animation with mecanim, you need to make the animations separated by "concepts" this means that when there are several animations finished, it's easier to make a simple animation and blend it with the others. If you are using Maya Animation layers you can ensure that this animations will blend perfectly.

On the next video you can see the animations on the ugliest way you can see them: splited. The hair, the wheels, the hands...all it's in different frames and this allow us to blend it later with mecanim. Don't worry, later I'll show the end result and it's quite better.




Once we got this animation exported on fbx, we import the asset on Unity. And we need to perform several steps. First of all On the rig tab we choose Generic (we choose this because for use the motorcicle and the character are one single model, if you have only a human character you must choose humanoid). And then click on th configure button. If you made the import correctly and you use CAT (on 3dMax) or HumanIK (Maya) the skeleton is assigned automaticaly and you don't need to change nothing. In other case you can assign the bones manually to its corresponding body part. This will allow you use the retargeting tools and the IK (only if you have something human like).


Then we go to the animation tab and edit the number of animations and choose the frames that limit each animation.

Once you have this you have the animations imported, but you can't use it yet. In order to use it you need an animation controller, so go to "Project" tab and create one, you can choose the name you want. Then, double click over the new controller and you can drag and drop the different animations in the current layer. Or create blend trees.

eh? What is a layer?


A layer is a sheet where you define some animations behabiour. For example:


The first animation or Blending tree that you create will be the default state and the animations will start here. The parameters will change this behaviour. In this case we have an idle animation. When the speed variable grow we change to "FromIdle" state. This state run until reach the 90% of the animation and is blended with the Run Blend tree. When the speed down to 0 we jump to the "To idle state" and once again we jump to Idle when we reach the 90% of this animation. here you have one example of these transitions:
 Maybe you have another question.

What a blend tree is?


The parameters allow to change from one animation to other but this is not the only use you can give it. A blend tree is a node that mix several animation depending on this parameter. In the following example you can see how we use the direction parameter to mix the turn animations with the default running one.


Now we need to to the same process on different layers. You can set the layers on override mode (and will rewrite the values for each bone) or you can set to additive (and will blend this animation with the layers before). Then by code you can choose which layers are or not active and you can set the values for each parameter. Here you have another layer example.

Then you need to attach this animation controller to a model and write a script that changes the parameters depending on your needs. And as a result we obtain this:



On this sample we don't use the shot animation because is not implemented yet. We hope to have it finised for the next delivery. And you can see that we are using simple pathfinding to ride only on the streets.

For more information about how mecanim works you can see the following video:
See you soon.

No comments:

Post a Comment