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
  • 8580 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

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