Calculated Animation with Expression Editor

Calculated Animation with Expression Editor

Maya 2012 Tutorial

 

How to Calculate and Set an Objects Rotation or Movement with Another Object's Motion in Maya

 

 

The Expression Editor is used to add scripting to your objects. The objects must be added to the workspace and named. The code is then added to the Expression Editor and the objects are connected mathematically.

 

In this example we will add two cylinders to the stage. The second cylinder is twice the radius of the first. As the first cylinder rotates, we want the second one to rotate at half the speed and in the opposite direction.

 

Step One

Add a polygon cylinder to the stage by choosing Create > Polygon Primitives > Cylinder. Make sure to include the options.

Step Two

Set the following values: Radius = 1, Height = 2, Axis Divisions = 20, Height Divisions = 1, Cap Divisions = 1, then press the Create button.

Step Three

Activate the Component mode by clicking the Component icon and click the Face icon. Press the 5 key to see your cylinder in shaded view.

Step Four

Select one of the faces, then shift select so you select every other face on the top of the cylinder.

Step Five

From the Polygon menu set, choose Mesh > Extrude.

Step Six

Pull the arrow upward to extrude the selected faces slightly upward. We will now be able to see as the wheel rotates. Press the q key to exit the Extrude mode.

Step Seven

Click the Object mode icon (F8) to return to the Object mode.

Step Eight

Duplicate the object by choosing Edit > Duplicate (Cmd/d (PC - Ctrl/d)).

Step Nine

In the Top view, activate the Move tool and drag the second cylinder next to the first cylinder.

Step Ten

Select the first cylinder, open the Channel Box and open the initial entry in object's Construction History. In this example it was named polyCylinder1.

Step Eleven

Change the Radius value to 0.5.

Step Twelve

In the Top view, move the cylinders so they touch.

Step Thirteen

Select the cylinders, one at a time, and note the name for each cylinder in the Channel Box. In this example they are named pCylinder1 and pCylinder2. pCylinder1 is the smaller cylinder.

Step Fourteen

Deselect both objects and open the Expression Editor by choosing Window > Animation Editors > Expression Editor.

Step Fifteen

Choose By Expression Name from the Select Filter menu.

Step Sixteen

Enter a name of rotateObj for your expression.

Step Seventeen

Type the following code in the Expression text box:

pCylinder2.rotateY=-0.5*pCylinder1.rotateY. Press Create, then press the Close button.

Step Eighteen

Select the Rotate tool (e key) and rotate the small cylinder around it's y axis. The second cylinder rotates at half the speed of the first cylinder.

Options Beyond Rotate

In addition to rotateY, there are several other object attributes you can access with the Expression Editor. The list includes:

visibility

translateX

translateY

translateZ

rotateX

rotateY

rotateZ

scaleX

scaleY

scaleZ

 

Stock Photos from 123RF