With Mecanim, it is also possible to blend animations for different body parts of a character. Let's see an example. You have a character that runs with a gun in its hand and you have a reload animation that the character performs each time its weapon is empty. When the character reloads, you want his upper body, actually its arms, to perform the reload action, while the lower body of the character, its legs, should keep running.
To achieve that in Unity, Mecanim features what are known as layers. Layers allow you to create masks for specific body parts of a character and apply animation clips only on those parts. A running animation that involves legs and arms can be blended with a reload animation that only involves the character's arms, the result being that the character keeps running with its legs, while its arms reload the weapon!
As layers require masks to work, in the next recipe, we will show you how to make one.
As we are not prototyping a 3D shooter here, we are not going to use actual animation clips for this recipe. We only show the required steps to use layers, for the time you will be willing to use them.
Have your project open in Unity; we left it with the Animator control panel containing the animations we scripted so far: Idle, Run, Walk, and Jump.
Avatar Mask
out of the character avatar we are already using. Let's begin by creating a new folder in the project and name it Masks
. We have done this operation several times; you won't need a reference picture…Avatar Mask
in this folder by right-clicking on the project panel and navigating to Create | Avatar Mask, as shown in the following screenshot:UpperBody
.The principle to make masks is quite easy: starting from the actual avatar of your character, you can add or remove body parts to be included or excluded from those affected by specific animation clips. Thanks to Mecanim, the operation is quite transparent for the user! Still, many more settings are available that we didn't mention here, and we encourage you to refer to the manual, available at http://docs.unity3d.com/Manual/class-AvatarBodyMask.html.
13.58.121.8