T u t o r i a l  -  Expressions Basics - 2

 Skill Level: Beginner 

The saga continues...
Now that you've got the basic idea of expressions, lets try something a little more involved.  In this tutorial you'll use expressions to keep an object exactly halfway between two other objects no matter where they move.  There are actually a lot of uses for something like this.  For example, this is what was used in the T Rex LazyAnimator setup to keep the body positioned correctly when the feet are moved.

The concept:
There are three expressions in this tutorial--one for each motion channel (X, Y, and Z).  Each expression takes the position of one of the objects, modifies it,  and feeds it into the third (which is a cheapskate and is in it for the money).  Alright, lets get moving...

The tutorial part:
1)
Load Whole_Object.lwo from Objects\Tutorial_General.

2)Clone it twice.  Rename them so it will be easier to tell them apart.  Name them Gaz, Danny, and Mick.

3)On frame 0, move Danny and Mick away from Gaz.

4)Go to the Command tab and click on New Variable.  Rename it to StayBetween_X by double-clicking the var line in the Expressions List.

5)Click on the X channel on Danny's Edit Sphere in the World View

6)On the Expression block, in the entry field for Exp, type ( and press enter, then right-click on the little gray box to the right of the Buffer field.  That should put the X channel for Danny in the field.  It should look like this:    ([Danny:xpos]

7)Add a+to the end of the expression and press enter, then select the X channel of Mick's Edit Sphere and right-click again on the little gray box to the right of the Buffer field.  Type ) at the end and press Enter.  The expression should now look like this:   ([Danny:xpos]+[Mick:xpos])

8) Now add /2at the end of the expression and press enter.  This tells it to divide the position by 2 so it will give a reading of the mid point.  The final expression should look like this:

9)Select StayBetween_X from the Expressions List, then go to the Add pulldown list on the Channels block and select Gaz.  Press the add button (the [+] button).

Now select xpos from the channel pulldown list at the bottom of the block (if it's not already selected).

At this point, Gaz will stay halfway between Danny and Mick on X when you move them.  Next, we'll do the same thing for Y and Z.  Most of the work is done already.

10)On the Variables block, click on Copy twice.  Rename the first copy to StayBetween_Y, and the second one to StayBetween_Z.

11)Select StayBetween_Y.  In the Exp field, change both xposentries to ypos by changing each xto a y, then select Gaz in the Expressions List for this expression, and select ypos from the channel pulldown list at the bottom of the Channels block (where you chose xpos in step 9, see image above).

12)Select StayBetween_Z.  In the Exp field, change both xposentries to zpos by changing each xto a z, then select Gaz in the Expressions List for this expression, and select zpos from the channel pulldown list at the bottom of the Channels block (where you chose xpos in step 9, see image above).

That's all!  Now, when you move either Danny or Mick, Gaz will stay halfway between.  If you're in an experimental mood, you can try entering in different formulas instead of the /2 and see what they do.

A completed version of this scene is located in the Scenes\Tutorials\ directory.  It's called Expressions_Basic_StayBetween_01.fxs

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