9

324 Chapter 12: Animation
Ex pres sion Contr oller Techni ques
This topic summarizes some useful expression
techniques. The following topics review
trigonometric functions and vector arithmetic. If
you’re familiar with these subjects you can skip
the review topics. Use these expressions when you
have applied an Expression controller using the
Assign Controller rollout in the Motion panel.
Commonly Used Ex pressions
This topic lists some expressions that you might
find useful in situations when you animate.
Circular Path
[ Radius * cos(360*Time),
Radius * sin(360*Time), 0 ]
where Time is one of the predefined time var iables
such as NT or S.
If you make the two Radius values unequal, you
get an elliptical path.
If you specify a nonzero Z component, the path
is no longer planar.
Following Another Object
[X, Y, Z] + Position
where Position is the Position controller of the
second object.
Thevector[X,Y,Z]canbeanoffsetfromthe
second object. (If it’s [0,0,0], the two objects
occupy the same position.) I t can also be a vector
expression that specifies some movement in itself.
Keeping an Object Bet wee n Two O bjects
(Position1 + Position2) / 2
where Position1 and Position2 are the Position
controllers of two objects.
The divisor 2 constrains the object to b e halfway
between the two other objects. Other va lues
constrain the object to other locations.
Bouncing Between Other Objects
(1+sin(360*Time))/2 * (Pos1-Pos2) + Pos2
where Time is one of the predefined t ime variables
such as NT or S; Pos1 and Pos2 are the Position
controllers of two other objects.
The subexpression (1+sin(360*Time))/2 is a
value that oscil lates between 0 and 1 over time.
(Pos1-Pos2) is the vector between t he two other
objects. Multiplying the two a nd then adding Pos2
asanoffsetlocatestheobjectalongthisvector.
Changing the Number of an O bject’s S egments
Based on Camera D istance
This expression varies the number of seg ments
in a cylinder based on the distance of a camera.
It is assigned to the cylinder’s Segments creation
parameter.
if ( (length(Camera-Myself) > 35),
3 + (50*Height) / length(Camera-Myself),
MaxSegs)
where Camera is the position con troller of the
camera; Myself is the cylinder’s position controller;
Height (= 70) is the cylinder’s height; MaxSegs
(=100) is the maximum number of segments.
When the camera is closer, more segments make
thecylindersmoother;whenthecamerais
distant, the smoothing is less important and fewer
segments render more quickly.
The if() function retur ns its second argument if
the first argument is true; otherwise, it returns its
third arg ument. In this example, if the camera is
more than 35 units away from the cylinder , the
expression calculates the number of segments; if
the c amera is 35 units away or closer, the number
of segments is the MaxSegs constant.