Vector Math functions are global methods that perform operations on arrays, treating them as mathematical vectors. Unlike built-in JavaScript methods, such as Math.sin, these methods are not used with the Math prefix. Unless otherwise specified, Vector Math methods are lenient about dimensions and return a value that is the dimension of the largest Array, filling in missing elements with zeros. For example, the expression add([10, 20], [1, 2, 3]) returns [11, 22, 3].
Argument type: vec1 and vec2 are Arrays.
Adds two vectors.
Argument type: vec1 and vec2 are Arrays.
Subtracts two vectors.
Argument type: vec is an Array, amount is a Number.
Multiplies every element of the vector by the amount.
Argument type: vec is an Array, amount is a Number.
Divides every element of the vector by the amount.
Argument type: value, limit1, and limit2 are Numbers or Arrays.
The value of each component of value is constrained to fall between the values of the corresponding values of limit1 and limit2.
Argument type: vec1 and vec2 are Arrays.
Returns the dot (inner) product of the vector arguments.
Argument type: vec1 and vec2 are Arrays [2 or 3].
Returns the vector cross product of vec1 and vec2. Refer to a math reference or JavaScript guide for more information.
Argument type: vec is an Array.
Normalizes the vector so that its length is 1.0. This is a short way of writing div(vec, length(vec)).
Argument type: vec is an Array.
Returns the length of vector vec.
Argument type: point1 and point2 are Arrays.
Returns the distance between two points. The point2 argument is optional. For example, length(point1, point2) is the same as length(sub(point1, point2)).
Argument type: fromPoint and atPoint are Arrays [3].
The argument fromPoint is the location in world space of the layer you want to orient. The argument atPoint is the point in world space you want to point the layer at. The return value can be used as an expression for the Orientation property, making the layer’s z-axis point at atPoint. This method is especially useful for cameras and lights. If you use this on a camera, turn off auto-orientation. For example, this expression on the Orientation property of a spot light makes the light point at the anchor point of layer number 1 in the same composition: lookAt(position, thisComp.layer(1).position)
If you are like me, you are an expressions newbie who might have assumed that "lookAt" would make any layer point at another layer. It does that in 3D, of course, but I hadn't found a 2D solution, so I hacked one together.
disclaimer: the last line of code is seriously flawed from an elegance standpoint, but at least it works. Maybe a moderator can help clean it up?
this wasn't quite behaving the way I wanted it to, so I had to subtract 90 degrees from the returned value AND multiply that value by -1. Apologies.
The basic idea here is to place this expression in the rotation property of any layer and have it automatically rotate to point at "Null 2".
to make this work point at whatever layer you want, just substitute "Null 2" with the layer name of the layer you want it to point at.
-------------------------copy and paste the text below-----------------
target = thisComp.layer("Null 2");
tx = target.transform.position[0];
ty = target.transform.position[1];
basex = transform.position[0];
basey = transform.position[1];
-((radiansToDegrees(Math.atan2(tx-basex,ty-basey)))-90)
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/en_US/AfterEffects/8.0/WS3878526689cb91655866c1103906c6dea-7a08.html
Comments
Comments are no longer accepted for After Effects CS3. After Effects CS4 is the current version. To discuss After Effects CS3, please use the Adobe forum.