Share
 
 

Example: To Animate an Object with an Expression Controller

The following example shows how you can use an Expression Controller to animate objects.

The example is broken into four stages:

  1. Creating the expression
  2. Modifying the expression
  3. Using a variable in the expression
  4. Animating the expression

To create an expression that moves a sphere in a precise circle:

  1. Create a sphere with Radius=15.0.

    You'll use Track View to create the Expression controller.

  2. In the active viewport, right-click the sphere and click Curve Editor.
  3. In the Hierarchy list, scroll down to the Objects branch and, if necessary, expand the Sphere001 branch so the sphere's Position track is visible. Click the Position label to highlight it.
  4. In the Hierarchy list, right-click the Position label and then click Assign Controller \ Node.

    3ds Max opens the Assign Controller dialog.

  5. Choose Position Expression from the list of controller types, then click OK.

    3ds Max opens the Expression Controller dialog.

  6. Replace the default expression by typing the following position expression in the Expression field:

    [100*cos(360*NT), 100*sin(360*NT), 0]

    The expression specifies a circular path for the sphere. NT is a variable that means "normalized time." Movement based on NT happens exactly once per the active time segment, regardless of how many frames are in the animation.

  7. Click Evaluate.
  8. Play the animation. The sphere moves in a circle about the world origin (0,0,0). The radius of the circular path is 100 units.

To change the radius of the circle:

    The two 100s in the position expression from the previous procedure specify the radius. To adjust the radius of the circle's path, create a symbolic variable to represent the radius. The variable has a constant value that is easy to edit.

  1. Reopen Track View and the Expression Controller dialog if necessary.
  2. In the Name field of the Expression Controller dialog, type radius Make sure Scalar is chosen, and then click Create.

    The variable name "radius" appears in the Scalars list of the dialog.

  3. Click Assign Constant.

    3ds Max opens a dialog titled "radius".

  4. Enter 150 in the Value field, and then click OK.

    The radius variable is now 150.

    Next you'll need to replace the literal value with the variable name to use the new variable in the expression.

To use the new variable in the expression:

  1. In the Expression field, change 100 to radius in both places. The expression should now look like this:

    [ radius*cos(360*NT), radius*sin(360*NT), 0]

  2. Click Evaluate.
  3. Play the animation. The sphere moves in a circle about the world origin (0,0,0). The radius of the circular path is 150 units.

To make the sphere rotate around a box:

  1. Create a box about 40 units square, and animate its position over three or four keyframes.
  2. Select the sphere.
  3. In the Name field of the Expression Controller dialog, enter boxposn. Choose Vector, and then click Create.

    The name "boxposn" is displayed in the Vectors list in the lower-left area of the dialog.

    Variable names are case sensitive; the variable name should be lower case.

  4. Click Assign Controller.

    The Track View Pick dialog is displayed. It shows the object hierarchy as it appears in the left side of Track View-Dope Sheet.

  5. In the Hierarchy list, highlight the Position controller for Box001 and then click OK.
  6. In the Expression field, add boxposn as an offset:

    [radius * cos(360*NT), radius * sin(360*NT), 0]+boxposn.

  7. Click Evaluate, and then click Close.
    Play the animation again. The sphere moves in a circle around the box and follows the box wherever it moves.
    Note: When you pick the Position controller for Box001 at step 5, the variable will hold the value of the position controller. That position value is relative to the parent node's (if any) transform. If you pick the node Box001 instead, the variable holds the world position of the Box001 (parent's transform + node's transform).

Was this information helpful?