Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Guest
May 23, 2013 May 23, 2013

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!

TOPICS
Expressions
7.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 23, 2013 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

...
Translate
Community Expert ,
May 23, 2013 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 25, 2016 Feb 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2016 Feb 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 25, 2016 Feb 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2016 Feb 25, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 09, 2022 Jul 09, 2022

Hey! I know this is many years down the line, but how would you go about mirroring just the x value here?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 09, 2022 Jul 09, 2022

Something like this, probably:

xRef = 640;
p = thisComp.layer("Left Face Null").transform.position;
value - [p[0] - xRef,0]
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 10, 2022 Jul 10, 2022
Hi,

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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 10, 2022 Jul 10, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 10, 2022 Jul 10, 2022

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]]
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 10, 2022 Jul 10, 2022
Yes, that worked! Only issue is they both have the same starting position
now. Is there any way I can offset the "left to right" circle's starting
point?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 10, 2022 Jul 10, 2022

Like this maybe:

p = thisComp.layer("right to left circle").transform.position;
x = (p[0] - p.key(1).value[0]);
value - [x,0]
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 11, 2022 Jul 11, 2022

Perfect, thank you!

How would you go about reversing the exact motion on the same object a few moments later. For example, the circle enters the frame from right to left with a certain velocity - how do I replicate the exact same velocity on the same object, as the circle exits frame from left to right
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2022 Jul 11, 2022

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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 11, 2022 Jul 11, 2022

Working perfectly now - thank you!

For some reason, when I alter the daley = .2 it does not shorten the time before reverse?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2022 Jul 11, 2022

delay = .2;

shortens the delay for me, as I would expect.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 11, 2022 Jul 11, 2022

Does this look correct?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2022 Jul 11, 2022

It does.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 11, 2022 Jul 11, 2022

I hada a stray keyframe messing things up. All good now. Deeply thankful for the help, Dan. All the best!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 12, 2022 Jul 12, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2022 Jul 12, 2022
LATEST

Hopefully, someone else will jump in, because I'm not sure what you're asking...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines