Hungry Pirhanas – Multi Select Expressions & LookAt

During NAB 2002 I came up with an expression setup and quite a lot of people asked me how expressions are used in this particular example. This example shows the lookat function together with an eval function and SelectionOrder in flame 7.6 (or inferno 4.6).

First, download the setup, model, and image files from here.

Untar the files into a directory of your choice.You will find the following files:

3DS File: piranha3d
Action Setup: piranhas
Textures: piranha.jpg and blue_piranha.jpg
(use geometry/load submaterials to change the texture if you like)

Here is a quick step by step description…

  • In action load in 3DS file: piranha3d.3DS (setup / import)
    name axis: rot_to_camera
  • add another axis and parent it to the 3D piranha axis
    name axis: first_object
  • select rot_to_cam and rotate it in y to make the piranha look towards the camera (rot y = 90)
  • optional : add a few more axis and name them second_object, third_object…etc… and parent them to rot_to_camera
  • add one more axis and name it ‘target’

your schematic should look similar to this now:

Select top view and reposition the 3D objects by influencing position using the parent axis (first_object, second_object, etc…)

Please note: the rotation values that you eventually set on the parent axis at this point will be overwritten by the expression later on. Still, I use rotation on first_object, second_object etc… just to set up the shot…but generally it’s enough to separate these guys in x and z position.

You should have a setup similar to this :Next:

  • Select all the parent axis (in this case 5) and switch to animation channel
  • Bring the anim channels to info view and swipe to get the big viewer (makes it easier to see what’s going on)
  • Click on ‘component’ so the channels get sorted by component and identify the rotation channels for the five axis. Reselect only the rotation channels for all the parent axis (5 in my particular case)
  • Type in expression that looks like this:

Here is a short description of what it is doing:

Inner part of expression: lookat
lookat (target.position, position)

In our example the target position is the single axis (named target) that controls the move of our piranhas. The observer position (second parameter of lookat function) will be the position of every 3D object itself. Now, instead of selecting all the channels separately and naming the observer position like that:

first_object.rotation = lookat( target.position, first_object.position)

second_object.rotation = lookat( target.position, second_object.position)

You can use the position parameter without referring to the object name. This will use the position parameter of the selected axis itself.
By using the parameter ‘position’ without further reference you can easily multiselect objects and refer to every single object’s position without retyping the name of the object (so called simplified expression). That’s fundamental for the setup that I’ve built here, otherwise I would have to type in 5 different expressions all referring to their object’s position.

Just multiselect channels and define the observer’s parameter with ‘position’.

Outer part of expression: eval
Eval ( lookat (target.position, position), frame – SelectionOrder * 10)
The eval function will offset the animation in time, here is how it works:
Eval (lookat (target.position, position), frame – SelectionOrder * 10)

New in here is the use of SelectionOrder, a keyword that will be substituted for every instance with the real value of the selection’s order. It will return 1, 2, 3 and so on in our expression. What eval basically does is to evaluate the value of a certain element at a certain time (frame). In this example the first piranha will have a nice rotation on frame 100 while the other piranhas just start to rotate.

Finally select the target axis and move it up in y direction using the axis menu controls (makes it easier to separate the axis). After you see the axis, move it around and all the piranhas will follow that movement….Cute, eh ?

The setup which comes with the tar file has an animated target over 200 frames. Scrolling through the timeline will show the effect of the eval function.

Have fun !!

 

Submitter: Elfi Bernt