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

Moving objects proportionally away from each others

New Here ,
Aug 14, 2019 Aug 14, 2019

I'm pretty new with expressions and this might be simple to make but I couldn't find an answer. So I have two nulls, which I want to move away and towards each others the same time. How can I accomplish that?

TOPICS
Expressions
887
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
Contributor ,
Aug 14, 2019 Aug 14, 2019

The actual way you'd write it depends a lot on what's going on in your scene.

The simplest way, though, would be to first pickwhip to the property you want to mirror, and then add "* -1" to it.

So:

thisComp.layer("Other Layer").transform.position * -1

In plain english, this is saying "Take _that_ value, and give me the negative value of it" -- but in a real scenario, you'd maybe only want to flip around the X, or just the Y, etc. Depends on what you're doing!

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
Engaged ,
Sep 13, 2019 Sep 13, 2019

To mirror the movement of the nulls around the center of a comp you subtract the position of the first null from the [width, height] of the comp. e.g. on the second null the expresssion would be

[thisComp.width, thisComp.height] - thisComp.layer("the first null").transform.position

You can see how this works if you imagine that the first null is at the bottom right of the comp, so its position would be the same as the comp width and the comp height, and so the expression would return [0, 0] which is the opposite corner. And if the first null is in the middle of the comp, the position would be half the width and half the height. If you subtract half the width and height from the full width and height the result is also half the width and height, so the two would be at the same point.

 

To mirror around an arbitrary point you subtract the position of the first null from twice the mirror point. E.g.:

let mirrorPoint = [123, 45]; //the mirror point - you could link it to a point control etc
mirrorPoint * 2 - thisComp.layer("the first null").transform.position
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 ,
Sep 13, 2019 Sep 13, 2019
LATEST

Away and towards each other??? That doesn't make much sense. 

 

Maybe you are looking for something like Dan Ebberts Elastic Connection

Maybe you are looking for something like Dan Ebberts Creating Trails

Maybe something like Dan's Random Motion

 

The expressions that have been given you will only move layers in opposite directions. Move layer 1 (null 1) up and to the right and layer 2 will go down and to the left. 

 

It would really help if you could explain exactly what you want to happen. If all you want to happen is one layer moves in the opposite direction of the first layer, and you want some control over the center then you probably want to position layer 1 and layer 2 where you want them to start, name Layer 1 Master and then add this expression to Layer 2. 

 

mstr = thisComp.layer("Master").transform.position;
cc = [thisComp.width/2, thisComp.height/2];
s = value + cc;
s - mstr

 

This will allow you to position the layers anywhere and adjust the collision point. 

 

Here is how it works: The mstr variable is the position of the Master layer. The cc variable is a hand way of calculating the composition center. The s variable is just the current value plus the comp center. Adding the current position of the second layer (the slave layer) keeps the layer from moving from its current position when the expression is enabled. This allows you to position the Master layer anywhere you want and put the slave layer anywhere you want, and then when you move them they will collide at the midpoint between their original position. You can animate either layers position property with keyframes and create some interesting movement. 

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