
Copy link to clipboard
Copied
So say that I have an icon that I animate on the Y-axis +40px, but instead of trying to hand key the other layer each time, is there an expression I can write to have the other layer move in the opposite Y direction the same amount of units (ex: -40px)?
Thanks!
1 Correct answer
You have to define what the y movement is relative to. For example, if you want one layer to mirror another layer's y movement since the first frame, you could do it like this:
p = thisComp.layer("leader").transform.position;
value + [0,p.valueAtTime(0)[1] - p[1]]
If you want to mirror it around a particular reference y value, it would be like this:
yRef = 540;
p = thisComp.layer("leader").transform.position;
value + [0,yRef - p[1]]
There are other variations/interpretations--it depends on what you're
...Copy link to clipboard
Copied
You have to define what the y movement is relative to. For example, if you want one layer to mirror another layer's y movement since the first frame, you could do it like this:
p = thisComp.layer("leader").transform.position;
value + [0,p.valueAtTime(0)[1] - p[1]]
If you want to mirror it around a particular reference y value, it would be like this:
yRef = 540;
p = thisComp.layer("leader").transform.position;
value + [0,yRef - p[1]]
There are other variations/interpretations--it depends on what you're after exactly.
Dan
Copy link to clipboard
Copied
Hi Dan,
Thanks for this, worked a dream.
However I hoped you could help with an addition to this. This currently works to move my y value in the opposite direction, but how can I add to this to move the x value in the same direction? I tried duplicating and changing y to x but to no effect.
Thanks,
Ryan
Copy link to clipboard
Copied
If you're talking about the first version, this should work:
p = thisComp.layer("leader").transform.position;
p0 = p.valueAtTime(0);
d = p - p0;
value + [d[0],-d[1]]
Dan
Copy link to clipboard
Copied
Sorry Dan my bad, I'm using the second version;
yRef = 640;
p = thisComp.layer("Left Face Null").transform.position;
value + [0,yRef - p[1]]
I just need to add something to this which would also move x but in the same direction, not the opposite.
Thanks,
Ryan
Copy link to clipboard
Copied
Something like this, I guess, but you'll need to adjust the value of xRef:
yRef = 640;
xRef = 640;
p = thisComp.layer("Left Face Null").transform.position;
value + [p[0] - xRef,yRef - p[1]]
Dan
Copy link to clipboard
Copied
Hey! I know this is many years down the line, but how would you go about mirroring just the x value here?
Copy link to clipboard
Copied
Something like this, probably:
xRef = 640;
p = thisComp.layer("Left Face Null").transform.position;
value - [p[0] - xRef,0]
Copy link to clipboard
Copied
thanks for getting back! In my case, I have a circle moving from right to
left. I want another circle to start from the same position, except move in
the opposite direction (left to right). It's a bit difficult because I
spent quite a lot of time animating the circle moving right to left (using
easy ease) and simply want to replicate the velocity of that movement, just
right to left.
Copy link to clipboard
Copied
Thanks for getting back! In my case, I have a circle moving from right to left. I want another circle to start from the same position, except moving the opposite direction (left to right). I spent quite a bit of time animating the circle moving right to left (easy ease mostly) and simply want to replicate the velocity of that movement, just right to left.
Copy link to clipboard
Copied
Maybe like this:
p = thisComp.layer("right to left circle").transform.position;
x = p.key(1).value[0] - (p[0] - p.key(1).value[0]);
[x,value[1]]
Copy link to clipboard
Copied
now. Is there any way I can offset the "left to right" circle's starting
point?
Copy link to clipboard
Copied
Like this maybe:
p = thisComp.layer("right to left circle").transform.position;
x = (p[0] - p.key(1).value[0]);
value - [x,0]
Copy link to clipboard
Copied
Perfect, thank you!
Copy link to clipboard
Copied
Something like this probably:
delay = .5; // pause before reverse
if (numKeys > 1 && time > (key(numKeys).time + delay)){
valueAtTime(key(numKeys).time - (time - (key(numKeys).time + delay)));
}else
value
Copy link to clipboard
Copied
Working perfectly now - thank you!
For some reason, when I alter the daley = .2 it does not shorten the time before reverse?
Copy link to clipboard
Copied
delay = .2;
shortens the delay for me, as I would expect.
Copy link to clipboard
Copied
Does this look correct?
Copy link to clipboard
Copied
It does.
Copy link to clipboard
Copied
I hada a stray keyframe messing things up. All good now. Deeply thankful for the help, Dan. All the best!
Copy link to clipboard
Copied
My last rookie question - I should've done this before animating, but how would you go about centering these two shapes within the composition? The align tool just forces the both of them ontop of each other in the middle.
Copy link to clipboard
Copied
Hopefully, someone else will jump in, because I'm not sure what you're asking...

