ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Time delay on only X axis

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Peter Viglietta
Time delay on only X axis
on Apr 9, 2018 at 10:06:54 pm

I'm trying to figure out how to do the following:
- I have Two layers, Layer A and Layer B.
-I animate the position of Layer A
- I want to parent ONLY THE X AXIS POSITION of Layer B to Layer A, with a time delay on it of however many frames I want.

I have used this expression on Layer B position before, but it parents both X and Y axis position... I wan. I have a spotty understanding of expression scripting and can't figure out how to use this same time of script to make it so that the Y axis position of layer B stays constant (or is able to be animated independently), and the X position transformation is parented to that of Layer A, with a time delay.

delayFrames = 8;
delay = framesToTime(delayFrames);
thisComp.layer("Layer A").transform.position.valueAtTime(time-delay) + [200,60]

I have also come across this script which seems to do what I want it to do, but I just don't understand enough about expressions to know how it is deciding which layer to parent to

A
delay = 5;

d = delay*thisComp.frameDuration*(index - 1);
p = thisComp.layer("Head").position.valueAtTime(time - d);
[p[0],value[1]]

Any help is much appreciated


Return to posts index

Steve Bentley
Re: Time delay on only X axis
on Apr 10, 2018 at 10:48:42 am

The key here is how to split up the x and y for the layer in question.
You can tell the layer its position this way:
[xvalue,yvalue];
You can also use the pick whip. Make sure the layer you want to access the position of has its position open, then in the layer you want to control, add an expression to the position parameter, erase what it puts in there and type [ then pickwhip the x value only of the other layer, add a comma, the pick whip the y value of the either the other layer's y value only or the y value of the layer you put the expression on. (there is another way too you will see below)
(the latter picking of the layer with the expression on it will only take the x value from the other layer and leave the y layer as you had it originally).

As for the code you mention:

delay = 5;
d = delay*thisComp.frameDuration*(index - 1);
p = thisComp.layer("Head").position.valueAtTime(time - d);
[p[0],value[1]]

Just step down through it - each line calculates one thing
delay= declares you want the variable delay to be equal to 5 (all lines end in a semicolon.)
d= calculates the time offset (index is the number of layers from the top, these start at 1)
p= calculates the position (both x and y) at the time calculated by the previous two lines.
Then the first element in [p[0], the x value (these elements start at 0, not 1 so y would be p[1]) is what you get in the last line, remember the x is that first one in the square brackets. And when you use the reserved variable called "value" you get what the layer with the expression was set to originally and in this case it becomes the second element (defined as 1) which is the y. So only the x is changed and the y stays what you set it to before the expressions went on, even if there are keyframes.
Both of those values together in the square brackets make the total position value because position must have two values inside it (or three for 3D, the Z)
You don't have to actually use an = sign when you finally declare that "I want the value of this layer's attribute to be this!", buy you could.
So:
final=[p[0],value[1]]
is the same as
[p[0],value[1]]

What ever value is calculated for a line in the code is the value that is passed to the layer.
AE doesn't mind that all the variables up to p= don't have two elements inside them because there is still more calculating to come in lines farther down.
If you just typed:

delay = 5;
d = delay*thisComp.frameDuration*(index - 1);

You would get an error because d is not in a format of [value0,value1] in other words [x,y] that position expects.



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]