T u t o r i a l  -  Expressions - Cycle

 Skill Level: Intermediate

This is an easy, yet useful expression...
Cycle
is one of those simple yet powerful expression functions that you're sure to find lots of uses for.  Here's what it does:  You create an animation, lets say twenty frames of a ball bouncing, then tie it to a slider so you can play through the animation fast, slow, forward or backward just by moving the slider.  This can be useful for repeating animations.

Note:  The difference between Cycle and the CycleBranch family of functions is that Cycle only works for the object it's applied to, whereas the CycleBranch family works for whole hierarchies.

Lets begin:
1)
Load our good friend,Whole_Object.lwo from the Tutorials_General directory, then create some animation for it.  For example, bounce it up and down for 40 frames.  You can move it on any axis (I've used Y here).

2)Create a Slider by selecting it from the pulldown list on the Add Items block on the File tab, giving it a name that makes sense to you, then clicking on Add.

3)Go to the Command tab and click on New Variable on the Variables block.

4)On the Expression block, give your expression a name.  I'm using Ball_Cycle.  Then select Cycle from the pulldown list.

Note: In a complex scene, you might have hundreds of expressions, so the more clearly you name them, the better.  Try to come up with a system and stick with it.  For example, you could use something like this:

ObjectName_SubSection_ExpressionType_Axis   Which might look like this in your scene: Kong_LeftLeg_Cycle_Xaxis

On the other hand, you might like to have the expression (or Function) first, like:  Cycle_Kong_LeftLeg_Xaxis.  Use whatever you like, but try to be consistent now so it'll make sense later.

5)Now it's time to fill in the arguments, and it has five of them.  Here's a description of them:

  1. The object that will control the playback of the animation.  In this case, the slider, Ball_Control.

  2. The specific channel of that object that will do the controlling.  In this case the xpos channel.

  3. The animated object that will be controlled.  In this case, Whole_Object.

  4. The channel of the animated object that will be controlled.  You can have it play back a group of channels (like all position, all rotation, etc.), or pick a specific one.  In this case we want all positions-- pos.

  5. The ending frame that you animated for that object to.  If you've animated frames 0-20, then you'd enter 20 here.  You can also use just a part of it, like if you've animated 100 frames, you can just use the first 30.  You can't choose the middle or the end only though.  In this case, our animation is 40 frames, so we put 40.

Here's what that looks like:

Ball_Control

 xpos

Whole_Object

pos

40

 

6) Right-click on the gray box next to the Functions pulldown list to apply the expression.


The final results in the Expressions List

That's all for the setup.  Now the ball's animation will be controlled by the X position slider.  If the slider is all the way to the left ( 0 ) the ball won't move.  As you move the slider from 0 to 1, the animation for the 40 frames will play, ending with the position for frame 40 when you are at 1 on the slider.  If you keyframe the slider at 0 on frame 0, then at 1 on frame 10, it will play the entire animation of the ball between those frames, speeding it up to fit.  If you keyframe the slider at 0 on frame 0, then at 1 on frame 100, it will play the ball animation slowly over those 100 frames.

Clean up your act:
If you were actually going to use this setup, there would still be a couple more things you'd want to do.  First, in Setup, rename the slider's X channel to Bounce.  Next, get  rid of those other slider channels by right-clicking on the colored channel dots for each of them on the Motion block on the Animate tab.  Since all you are using is one channel, there's no need to clutter up the World View with the rest.

For a completed example of this scene, load Expressions_Cycle_01.fxs from the Tutorials scene directory.

Converted from CHM to HTML with chm2web Pro 2.82 (unicode)