Skip to main content
May 23, 2013
Answered

Noob Question: Move a layer in the opposite direction of a different animated layer

  • May 23, 2013
  • 1 reply
  • 8651 views

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!

Correct answer Dan Ebberts

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

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
May 23, 2013

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

Participating Frequently
February 25, 2016

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

Dan Ebberts
Community Expert
Community Expert
February 25, 2016

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


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