After Effects Expression Linear Position

  1. After Effects Expression Linear Position Test
  2. After Effects Expression Linear Position Example
  3. After Effects Expression Tutorial

The Easy Expression to add to Position, for wiggle in X axis only (the red axis above) is: x = transform.position 0; y = transform.position 1; w = wiggle (2,100); w 0,y; In the example expression above, 2 is the amount on wiggles per second, 100 is the maximum wiggle value in the X axis. Here are some alternative, tried and tested. The index expression isn’t rocket science, but it is nevertheless an incredibly powerful tool in After Effects. Essentially the index expression returns a value based on the layers position in the timeline. For example, a the 4th layer in a timeline will return a value of 4.

If you want to use the speed/velocity of a layer's movement to drive an effect ..
After Effects CS3
Useful things
Expressions
Views: 10948
Permalink
If you want to take the speed for a layer's postional value, you can use the following expressionThis expression has the advantage of using the speed information coming from a layer's position and applying it to whatever parameter you want it to influence.
For example, if you are moving a layer through a comp, and want the speed of the movement to influence the brightness of the layer, you would just copy and paste this expression to the 'Brightness and Contrast' filter, in the Brightness parameter.
Why the /3-50?
Simply because the speed of the layer's position is expressed in 100's (i.e the speed can go from 0 pixels/s to a quite large amount), whereas the brightness goes from 0 to 100. So if you divide the values for speed by 3, you arrive to a decent value for brightness (the brightness won't be overblown).
The -50 adds more control to this, putting the brigthness down by 50. You could change this for any other number, depending on your needs, but you could also not use it and divide the speed by 5, or more.
by malex

Keywords

speed, velocity, movement
(Min. Version: After Effects CS3, Category: Useful things, Type: Expressions)

These two expressions are beyond useful. The way they work finally clicked in my head recently. (I had a good idea of what toComp() did because it’s an expression that a lot of tutorials use. Drawing a line between two 3D nulls with the beam effect, for instance.)

toWorld() does essentially what toComp() Ibm informix jdbc drivers. does, but with the third dimension. So, knowing that– what is it that they do? Well, I was just about to explain it! Calm down. Holy Ravioli.

After Effects Expression Linear Position

These two expressions basically calculate the whereabouts of a layer after it has been parented to another layer. Let’s think about it in terms of nulls….

We have NullA, NullB, NullC. All 3D layers. We’re going to parent NullB to NullA… and then move NullA around. We find that the values in the Position property of NullB don’t change at all. This being the case, if we want NullC to be exactly where NullB is (using expressions), we can’t simply expression-pick-whip to NullB’s Position– because that number doesn’t fully represent where NullB is in space.

toWorld() is built for this problem. We can use something like thisComp.layer('NullB').toWorld([0,0,0]) in the Position property of NullC to access the point in space where NullB is located– after NullA has been moved around, rotated, and scaled.

I’ve started to use toWorld() in place of transform.position in some of my expression set-ups, to save myself the headache later on– in the event some of my layers need to be parented to other layers.

Hey! Let’s do something useful now!

Here is an expression that makes a layer travel between two other layers, based on the value of a slider (between 0 and 1, more specifically).

THE SETUP

We’ll use NullA, NullB, and NullC. Let’s unparent NullB from NullA (though, it doesn’t need to be unparented). NullC is going to exist between NullA and NullB. Where NullC exists (Closer to A? Closer to B?) will be driven by a Slider Control. We’ll call it weight. We’re going to want to edit the Slider Range in the “Edit Value…” window, so instead of being set to the default 0 to 100, it will now be 0 to 1. This will just make it easier to control when we’re dragging this value.

Let’s get our keyboard fingers dirty! (Ugh. Gross.) We’re adding this expression to the Position property of NullC. I’ll paste the finished product here, and then I’ll explain it.

a=thisComp.layer('NullA').toWorld([0,0,0]);
b=thisComp.layer('NullB').toWorld([0,0,0]);
wh=thisLayer.effect('weight')('Slider');
aW=a*wh;
bW=b*(1-wh);
aW+bW

After Effects Expression Linear Position Test

There are two parts, essentially. First, we’re setting up variables for NullA, NullB, and our weight Slider. Second, we’re using a bit of math to calculate the positions between NullA and B. To simplify the idea, consider the following: if you wanted to just have NullC exist exactly in the middle of A and B, you’d do something like this:

a=thisComp.layer('NullA').toWorld([0,0,0]);
b=thisComp.layer('NullB').toWorld([0,0,0]);
(a+b)/2

After Effects Expression Linear Position

Which would be the same thing as this:

After Effects Expression Linear Position Example

a=thisComp.layer('NullA').toWorld([0,0,0]);
b=thisComp.layer('NullB').toWorld([0,0,0]);
(a*.5)+(b*.5)

After

To vary C’s proximity to either A or B, we’re just affecting those .5’s– making sure they always add up to 1. If we want the C to be closer to A, we’ll just give that side more “weight”– .8, let’s say… and that would leave .2 on the B side. In our expression, this bit is handling that math:

After Effects Expression Tutorial

aW=a*wh;
bW=b*(1-wh);

The exciting part is that the values BEYOND 0 and 1 on the slider will give you positions for NullC that are still in-line with NullA and NullB.

That’s it! Post questions if you have them!

After Effects Expression Linear Position

I’ve started a GitHub account— so I’ll be publishing the expressions I post here to “Gists”, in case there’s ever a problem copy/pasting my code from WordPress.