<p>By having the layer parented you make it a bit harder. If you want the second layer to follow the x coord of the first layer, but mirror the y coord this will do it (without the second layer being parented)</p>

<pre><code>var centerY = thisComp.height/2;
var p = thisComp.layer("the name of the controlling layer").transform.position;
[p[0], centerY - p[1]]
</code></pre>

<p>If do you need the second layer to be parented the following should work. Because the distance from the parent to the centre point is the same as the distance from the center point to the child, we can just multiply it by two to get the y distance in the layer space of the parent:</p>

<pre><code>var centreY = thisComp.height/2;
[value[0], 2*(centreY - parent.position[1])];
</code></pre>

<p>Both of these expressions will mirror around the centre of the comp vertically. You could mirror around an arbitrary y point by specifying it on the first line instead of <code>thisComp.height/2</code>, e.g.: <code>var centerY = 1234</code>. </p>

<p>You could also use another layer as the control of the mirror point by using this instead of that expression: <code>var centerY = thisComp.layer("name of center control layer").transform.position[1]</code></p>

CC BY-SA 3.0
2017-01-07T12:13:45.047Z
2017-01-07T22:33:10.243Z
2017-01-07T22:33:10.243Z
stib
<p>Maybe try the Kaleidoscope or mirror effect instead?  Might achieve the same thing much more quickly.</p>

CC BY-SA 3.0
2017-01-07T08:28:20.660Z
2017-01-07T08:28:20.660Z
tomh
<p>I have a composition in After Effects (CS6) that contains 2 objects that are usually a set distance apart. I am looking for an expression or other method to automatically move one layer by the same amount as its parent, but in the opposite direction (as in if the parent goes up 5 px the child should go down 5 px). So far I haven't been able to figure this out, but I am very new to expressions.</p>

<p>Thanks!</p>

<after-effects><after-effects-expressions>
Expression for inverse parenting on Y axis in after effects
Mr_Ymmit
# Expression for inverse parenting on Y axis in after effects

(Asked by: username_0 on 2017-01-06)

I have a composition in After Effects (CS6) that contains 2 objects that are usually a set distance apart. I am looking for an expression or other method to automatically move one layer by the same amount as its parent, but in the opposite direction (as in if the parent goes up 5 px the child should go down 5 px). So far I haven't been able to figure this out, but I am very new to expressions.

Thanks!

**Tags:** after-effects, after-effects-expressions


---

## 2 answers

### Answer by username_1 on 2017-01-07. Score: 1

By having the layer parented you make it a bit harder. If you want the second layer to follow the x coord of the first layer, but mirror the y coord this will do it (without the second layer being parented)
var centerY = thisComp.height/2;
var p = thisComp.layer("the name of the controlling layer").transform.position;
[p[0], centerY - p[1]]

If do you need the second layer to be parented the following should work. Because the distance from the parent to the centre point is the same as the distance from the center point to the child, we can just multiply it by two to get the y distance in the layer space of the parent:
var centreY = thisComp.height/2;
[value[0], 2*(centreY - parent.position[1])];

Both of these expressions will mirror around the centre of the comp vertically. You could mirror around an arbitrary y point by specifying it on the first line instead of thisComp.height/2, e.g.: var centerY = 1234. 
You could also use another layer as the control of the mirror point by using this instead of that expression: var centerY = thisComp.layer("name of center control layer").transform.position[1]


---

### Answer by username_2 on 2017-01-07. Score: 0

Maybe try the Kaleidoscope or mirror effect instead? Might achieve the same thing much more quickly.


---

