Expression Controller Techniques

This topic summarizes some useful expression techniques.

See Also

Commonly Used Expressions

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 variables 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.

The vector [X, Y, Z] can be an offset from the second object. (If it’s [0,0,0], the two objects occupy the same position.) It can also be a vector expression that specifies some movement in itself.

Keeping an Object Between Two Objects

(Position1 + Position2) / 2

where Position1 and Position2 are the Position controllers of two objects.

The divisor 2 constrains the object to be halfway between the two other objects. Other values 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 time 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 oscillates between 0 and 1 over time. (Pos1-Pos2) is the vector between the two other objects. Multiplying the two and then adding Pos2 as an offset locates the object along this vector.

Changing the Number of an Object’s Segments Based on Camera Distance

This expression varies the number of segments 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),

where Camera is the position controller 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 the cylinder smoother; when the camera is distant, the smoothing is less important and fewer segments render more quickly.

The if() function returns its second argument if the first argument is true; otherwise, it returns its third argument. In this example, if the camera is more than 35 units away from the cylinder, the expression calculates the number of segments; if the camera is 35 units away or closer, the number of segments is the MaxSegs constant.

The values in the second argument are chosen so that as the distance decreases toward the threshold of 35, the number of segments increases toward MaxSegs. The addition "3+" ensures that the cylinder always has at least three segments, even when the division rounds to zero (Segments is an integer).

NoteTo the expression, it doesn’t matter whether the camera is moving, or the cylinder, or both.