(Page 2 of 2 pages for this article < 1 2)
Sunday, March 07, 2010
Deeper Modes of Expression, Part 3: Deeper Into Arrays
Chris Meyer | 03/07
How to translate values between parameters that have different dimensions.
Measuring Tape
After Effects provides a pair of “length” expression methods which can measure either the distance between a Position value and the position 0,0 (or in the case of 3D, 0,0,0), or the distance between two different Position values. Oldtimers who remember the Motion Math “span” script may start to imagine some uses for this method.
We tend to use the form length(pos1,pos2). In the lefthand image below, we used it to tell us how far the spaceman is from the wireframe planet he is swinging by – even when the position of both are changing, and even if they are in 3D. To display the result onscreen, we applied the following to the value of Text > Numbers:
pos_1 = thisComp.layer(“spaceman”).position;
pos_2 = thisComp.layer(“globe”).position;
length(pos_1,pos_2)
(You can also apply this expression to the Source Text parameter of a text layer. It can get a bit messy, as you get all of the internal digits to the right of the decimal point. We will discuss using expressions with text in a later installement.)
We wrote this as a three-line expression for the sake of clarity. You could write this in one line, using the pick whip to help you fill in the values between the brackets rather than typing it by hand.
 -2.jpg)
In these two examples, we used the Numbers effect and the expression length(pos1,pos2) to help measure the distance between 2D or 3D objects. Spaceman courtesy Classic PIO/Nostalgic Memorabilia.
Constant Size
To keep a layer’s apparent size constant at varying distances from a 3D camera, apply the following expression to its Scale:
distance = length(sub(position, thisComp.activeCamera.position));
scale * (distance / thisComp.activeCamera.zoom)
Here’s Looking At You
Whereas the length expressions measure the distance between two points, the “look at” expression finds the angle between two points. You might already be familiar with the ability to have a layer, light, or camera auto orient along its path, or to have a layer auto orient toward a camera; the look at expression allows one layer to auto orient toward another layer.
For the lookAt expression to work, it must be applied to the Orientation property of a layer that has its 3D Layer switch enabled. To apply it, expose Position and Orientation for the layer you want to apply it to, Position for the layer you want to look at, and follow these steps:
- Enable expressions for the Orientation property of the layer doing the looking.
- Type lookAt
- Drag its pick whip to the Position property of the layer you want to look at.
- Type a comma, and either drag the pick whip to this layer’s Position, or just type position
- Type ) and press Enter.
(By the way, if you use the expression language menu to help write a “look at” expression, note that it has the Position properties backward: It says lookAt(fromPoint, atPoint), but this will make the back of the layer face toward the layer of interest.)
Depending on how your layer was designed, you may find it is facing - rather than pointiong at - the other layer. You can fix this by scrubbing the X, Y, or Z Rotation values as needed to reorient the layer to point as desired. In the example below, we set the arrow’s Y Rotation to 90 degrees to get it to point in the right direction.


The normal lookAt expression causes a layer to face – rather than point at – another layer. To reorient a layer, scrub its Rotation properties; + or –90 degrees for one of these will fix your problem.
Next Installment: Space Conversions
That was a lot to chew on. But if you made it past the theory on page to the useful length and lookAt expression methods above, now you have a couple more handy tools in your pocket.
In the next installment, we’ll tackle the tricky subject of how to translate between a composition’s “world” space and a layer’s “local” space, or between 2D and 3D dimensions. Until then…
The content contained in Creating Motion Graphics with After Effects - as well as the CMG Blogs and CMG Keyframes posts on ProVideoCoalition - are copyright Crish Design, except where otherwise attributed.
(Page 2 of 2 pages for this article < 1 2)
You must be registered to comment. This is an effort to reduce spam. Please REGISTER HERE.
|