Join Sue Blackman for an in-depth discussion in this video Creating layer masks, part of Animating Characters with Mecanim in Unity 3D.
With a lot of the basics under your belt, we're going to star looking at more of Mecanim's features. In this video, we'll be invstigating masks and layers. Masks allow you to control different parts of your character separately. An example would be firing a weapon. he could fire from a walk or a strafe or a run, rather than creating three more clips with the locomotion and the gun-firing animation, You can just override the arm that holds the weapon with the fire weapon clip. We'll start by having our character do something a bit more benign.
If you look at the robot 2 character's animation clips, you can see that he has a few head animations and an arm animation. We'll use his arm wave clip. R2_wav. So the first thing we need to do is make a mask for just the arm. Let's select the mech anim assets folder, and then from the right click menu click create, and from down near the bottom choose avatar mask.
And let's name this one Arm Right Mask, and Enter. In the inspector, we want to use the top one, Body Mask. So let's click to open it, and this brings up the body image where we can see the choices. We can make a mask for the root, shown as that shadow area down at the bottom, or feet, head, body, arms, hands, legs, and IK. Inverse kinnematic goals if you're using Pro.
Let's start with the right arm. If you click inside the body's boudning box area, all parts turn red. They're deselected. If you click again, they're toggled back on. So let's toggle them off and go 'head and click the right arm. And the right hand. That's the characters, by the way. That's all there is to it. So let's go ahead and duplicate this mask with control D and name this one head mask.
Head mask, as you're probably going to guess, is just the head. And yeah, we're going to have a few of these, so let's go ahead and create a new folder inside the Mechanim Assets folder. New Folder, and we'll call this one Masks and drag our new masks into it. The robots animations were all prepared with the intention of using them with masks. Only the body parts that will be included with the masks were animated, but sometimes, you may have a full animation and decide that you only want to use parts of the body with it for a different purpose.
To enable you to see the results of masking in specific clips, you can make use of the body mask in the animation section where the clip's set up. Let's check this out with an animation that's not very subtle. Let's use the box man's bog walk clip. And, we're actually going to use better box man a. And we're going to select his bog walk. And beneath the regular clip stuff, you'll find body mask. When we open it up. And we've got that same body mask that we saw before. Now I'm going to float my preview window and we're going to have a little fun with him.
So if we click Play, let's deselect the parts one by one, and you can see what's happening here. This gives you a way to isolate the parts and see what it's going to do with your clip. Then you may decide that this guy only needs a few body parts. Now there's nothing very useful out of this character by Isolating the parts, but you can see how you could use just part of an animation that already existed, and be able to create a mask for it.
This isn't a mask yet, but it just allows you to see what the character's going to look like when he does have a mask. That matches it. So basically, now I'd create an actual avatar mask with the parts that I wanted. In that case, you know, maybe it was the body, the head, and the left arm and hand. Anyway, now that we have a couple of masks, we'll be able to use them in the animator's layers.
- Importing characters and setting scale
- Setting up the controller
- Creating transitions
- Scripting the controls
- Adding layers and layer masks
- Handling nonhumanoid appendages
- Configuring blend trees
- Controlling states with speed
- Adding a multistate jump
- Targeting with IK (inverse kinematics)
- Setting up generic rigs
- Testing the character in the game