Skip to main content
Inspiring
October 11, 2021
Answered

Expression to move x-position negative to null?

  • October 11, 2021
  • 3 replies
  • 625 views

Hi there, 

 

How do I make one object to move the opposite way of another? 

 

An example of what I want to achieve: In a 1000x1000 comp with two objects placed in the middle, in one of the objects (or perhaps a main null) I enter +200 on the X-position. Object 1 moves to x-position 700, object 2 moves to x-position 300. 

 

All the best

/Pär  

 

During the hours I have searched for an answer for this I found

This topic has been closed for replies.
Correct answer Mylenium

My mistake. I overlooked that it's a vector value and the components need to be addressed. I usually isolate this in the first step, so I missed it. This should work:

 

[pOut[0],p1[1]]

 

Mylenium

3 replies

Mylenium
MyleniumCorrect answer
Legend
October 11, 2021

My mistake. I overlooked that it's a vector value and the components need to be addressed. I usually isolate this in the first step, so I missed it. This should work:

 

[pOut[0],p1[1]]

 

Mylenium

Inspiring
October 11, 2021

Absolutely fabulous! Thank you both!

Mylenium
Legend
October 11, 2021

Position data is a 2D or 3D array and needs to be addressed accordingly:

 

[X,Y]

 

In your case that translates to

 

center = [thisComp.width,thisComp.height]/2;
p1 = thisComp.layer("Object 1").position;
pOut=center*2 - p1

 

[pOut,p1[1]]

 

Mylenium

Inspiring
October 11, 2021

Thanks for the input Mylenium! 

 

I tried it but get an error-message saying pOut has an undefined value. Yet that's what you already defined in that expression right? See attached image. 

 

 Thanks

/Pär

Dan Ebberts
Community Expert
Community Expert
October 11, 2021

There are a couple of ways, depending on how you have things set up. In the simplest way, you have to define a reflection point. In this example it will be the center of the comp. You would apply this expression to Object 2's position and it would keep Object 2 on the opposite side of the reflection point from Object 1:

center = [thisComp.width,thisComp.height]/2;
p1 = thisComp.layer("Object 1").position;
center*2 - p1

 

Inspiring
October 11, 2021

This is great Dan! Thanks. 

 

How do I keep the Y-position to move the same meanwhile the x-position uses your brilliant expression? 

 

After your expression, I tried to add: 

// for horizontal layer
c = thisComp.layer("the layer you want to mirror").position;[value[0],c[1]];

 

That made your expression to not work anymore 😕😕