Creating a Lean Control

Learning to create custom attributes for your rigs

The goal of a functional character rig is to provide the animator with the maximum control from the simplest interface.

 

This tutorial will demonstrate how to create custom object attributes. We will also be writing some simple expressions to connect those attributes to the node we want to control.

 

Let's say we want to create a control that will allow the animator to lean this pumpkin character from side to side.

 

pumpkin character

 

Here's the leaning effect that we are trying to achieve:

 

leaning effect

 

As you can see below, simply selecting the geometry and rotating it from a single pivot point will not do:

 

single pivot

 

When the pumpkin leans to the left, we want him to pivot from the contact point on the left side. And when he leans to the right, he should pivot from the contact point on the right. If he always rotates from the same pivot point in the middle, we have intersection with the ground plane.

 

Of course, the animator could always just rotate and translate the pumpkin by hand. But aside from being a lot of work, it's bound to look "floaty" in the end. Our task is to make the animator's job easier.

 

Ok, so how do we achieve multiple pivot points?

 

The best way is to parent the pumpkin under a couple of null nodes. Select your object and group it twice. Select the inner group and rename it "LeanLeft." Select the outer group and rename it "LeanRight." Now select the pivot points and move them where we want them. (On a PC, hit the "insert" button to toggle the pivot mode.

 

Like so:

 

placing left pivot

 

placing right pivot

 

Now, we can select the LeanLeft node and rotate to make the pumpkin lean to the left. Select the LeanRight node to make the pumpkin lean to the right.

 

lean by hand

 

Excellent! We have the desired effect in place using the group nodes with different pivot points. The pumpkin is able to lean from side to side. But it's still not easy to animate. We don't want the animator to have to be selecting different groups to lean each way. It would be great if we could control the lean with one attribute.

 

Here's what we do:

 

Create a NURBS curve, locator, or null object and name it "LeanControl." In the Channel Box, right click and select "Add Attribute." The following window will open:

 

add attribute

 

Name the attribute "pumpkinLean" (or whatever else you want), and make sure the data type is set to "float."

 

Now we have a control object with our own custom attribute.

 

control object

 

Unfortunately, it doesn't do anything yet. But we have plenty of options. We can use it to control other values in Maya using the connection editor, various utility nodes, set driven keys, or expressions. Today, we're going to use expressions, as they offer what we need to create the lean control.

 

Go to Window > Animation Editors > Expression Editor. We're going to enter some simple expression functions to connect our custom attribute to the lean nodes.

 

Start out with:

 

LeanLeft.rotateX = LeanControl.pumpkinLean;

 

The syntax there is pretty self-explanatory. Just remember to finish every line with a semi-colon. Click "create" at the bottom of the expression editor to create your expression. Now, when you scrub through the values of our custom attribute, you should see the pumpkin rotating.

 

initial results

 

initial results

 

You'll notice that it's still not quite what we want. The problem is that the pumpkin is always rotating about the left pivot point. We want it to rotate around the left pivot point when he leans in one direction, and the right pivot point when he leans the other. In algebraic terms we need to create a "piecewise function."

 

To do that, we need to change the expression slightly.

 

LeanLeft.rotateX = clamp(0,360,LeanControl.pumpkinLean);

 

What exactly did we do? We clamped the input between the values of 0 and 360. So if LeanControl.pumpkinLean = 23, then LeanLeft.rotateX = 23. But if LeanControl.pumpkinLean = -17, then LeanLeft.rotateX = 0. the value is clamped.

 

Click "edit" to update the expression. Now, when you scrub the values of our custom attribute, values between 0 and 360 lean the pumpkin to the left by rotating the LeanLeft node. When the value dips below 0, the pumpkin stays still.

 

Now we just need to add the right side to our expression. The final expression should look like this:

 

LeanLeft.rotateX = clamp(0,360,LeanControl.pumpkinLean);

LeanRight.rotateX = clamp(-360,0,LeanControl.pumpklinLean);

 

Again, don't forget the semi-colon at the end of each line. Click "edit" to update the expression.

 

Now you can scrub the control and watch the pumpkin rock back and forth! By using the piecewise function, we are able to control different nodes with one attribute, depending on the attribute's value. With a little creativity, this method can go a long way in your character rigs.

 

final result

 

We're done!

 

You can download the final control here: Lean Control

 

Hopefully this introduction was enough for you to be able to play around with custom attributes and expressions on your own. When I was first learning character setup, I found Chris Maraffi's book extremely useful: Maya Character Creation. It's a great intro to the principles of creating your own rig.

 

Thanks for visiting my site! I hope that you enjoyed the lesson. Feel free to email me with any questions or corrections. I hope you'll visit again and check out some more tutorials. Or check out my weblog: Set Driven Key, for animation news, updates, and Maya tips.