Expressions, part 2
Alright.
What we know is where the camera starts and ends. In After Effects, all the elements in 3D space have an x, y and z position, which is written like this
thisComp.layer("Roving Camera").position[0, 1, 2]
thisComp —the selected composition
layer("Roving Camera") — name of layer (which was actually a “virtual camera”)
position — the attribute we are editing
[0, 1, 2] — the three elements in a position attribute, that is, x y and z.
So, if I have a layer named ‘Han Solo’ and i wanted to make the variable ‘t’ its y position I would write
t = thisComp.layer("Han Solo").position[1]
Or, if I have a layer named ‘Ghengis’ and i wanted to make the variable ‘t’ its z position I would write
t = thisComp.layer("Ghengis").position[2]
So now we want the opacity of a layer (lets call it Jedi) to be proportional to how far away the Roving Camera is. We know the start point of the Roving Camera (an x, y, z coordinate) and we know its end point (and x, y, z coordinate in front of layer Jedi)
Now how to we find the distance between two points?
And so what about a z point? Well, the equation for that is
Distance between two points in 3D space = ![]()
So now we know the distance between the Roving Camera and layer Jedi.
in After Effects expression language this is:
a = thisComp.layer("Roving Camera").pointOfInterest[0];
b = thisComp.layer("Roving Camera").pointOfInterest[1];
c = thisComp.layer("Roving Camera").pointOfInterest[2];
d = thisComp.layer("Jedi").position[0];
e = thisComp.layer("Jedi").position[1];
f = thisComp.layer("Jedi").position[2];
x = Math.pow(a-d, 2)+Math.pow(b-e, 2)+Math.pow(c-f, 2);
x = Math.sqrt(x);
(I’m using the Camera’s Point of Interest value instead of position as I what the layer Jedi to be fully opaque when the camera is in front of it rather than being on top of it. )
Now, what i did next was do another pythagorean distance equation, this time with a layer at the start position and the layer Jedi
g = thisComp.layer("Start").pointOfInterest[0];
h = thisComp.layer("Start").pointOfInterest[1];
i = thisComp.layer("Start").pointOfInterest[2];
m = Math.pow(d-g, 2)+Math.pow(e-h, 2)+Math.pow(f-i, 2);
m = Math.sqrt(m);
Now I’ve got two distances, the total distance (m) and the distance of the camera to the final layer Jedi (x)
I can express the camera distance as a percentage of the final distance
x = x / m;
x = x * 100;
And because I want the end to be 100% opaque, I subtract the total amount by the traveled distance.
x = 100 - x;
Now what we found was that we wanted to slightly see all the objects at the start, so I made a condition that the layer Jedi is always 10% opaque.
if(x<10){
x=10
}


July 31st, 2007 at 3:34 am
I like math.
November 14th, 2007 at 12:05 pm
[...] what we’ve been up to: simon mentions corey for the first time. editing their wedding video. working with motion – some of simon’s dorkiness [...]