How do I link the rotation of an object to the scene time?

new.gif MAXScript Frequently Asked Questions

A user asked:

I want to create a simple expression that will rotate an object based on the current time.

Answer:

You can assign a Float Script Controller to the respective rotation sub-controller and use the currentTime global variable to get the time.

For example,

if you want to rotate the object about its X axis, you should assign a Float Script controller to the .rotation.x_rotation.controller property:

obj = Teapot()

obj.rotation.x_rotation.controller = Float_Script()

obj.rotation.x_rotation.controller.script = "currentTime"

 

This will rotate the object, but the rotation will be very fast because the time value is taken as radians, causing a full 360 degrees rotation every 6.28 frames!

To take the time as degrees,

you can use

obj.rotation.x_rotation.controller.script = "degToRad currentTime"

 

This will rotate the object 360 degrees in 360 frames. You can of course multiply the result by any factor to control the exact speed,

like

obj.rotation.x_rotation.controller.script = "0.1 * degToRad currentTime"

 

will rotate the object at 360 degrees in 3600 frames...

 

Another way to do the same is using the Float Expression controller. Unfortunately, it is not completely scriptable.

For example

obj = Box()

obj.rotation.x_rotation.controller = Float_Expression()

 

will assign a float expression controller to the X rotation track.

Now you can open the Expression window by going to the Motion tab, right-clicking the controller and selecting Properties...

Enter the expression

degToRad(F)

 

and press the Evaluate button.

The result should be the same as the Flot Script controller version.

 

See also

Frequently Asked Questions