Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Moving an Object Relative to Others

  • Moving an Object Relative to Others

    Posted by Tynan Humphrey on January 19, 2018 at 1:25 am

    Hi!

    I have a cloud of 2D layers spread across 3D space. The front/center layer is the controller. I used this tutorial as an entry point substituting position for scale. What I want instead is for the layers to move relative to the objects around them. Does that make sense? If the object in the top left of the cloud moves toward the center object, all objects between the two shift proportionally. That said, ideally the initial position is set with the layer’s position value, not procedurally generated by the expression.

    Any pointers would be amazing!
    Thanks.

    Tynan Humphrey replied 8 years, 3 months ago 2 Members · 2 Replies
  • 2 Replies
  • Kalleheikki Kannisto

    January 20, 2018 at 12:53 pm

    Not quite picturing what you want to achieve. An image would help.

    Do you want two of the layers to control the motion (the “center one” and the last one)? Are the rest in a straight line in between?

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Tynan Humphrey

    January 23, 2018 at 5:55 am

    Here’s the expression I ended up using. It scales well and seems fairly lightweight. Let me know if you see any optimizations.

    //Initial position variables
    initCtrl1=thisComp.layer("Ctrl1").transform.position.valueAtTime(-1);
    initCtrl2=thisComp.layer("Ctrl2").transform.position.valueAtTime(-1);
    objPos=transform.position;

    //Current positions variables
    newCtrl1=thisComp.layer("Ctrl1").transform.position;
    newCtrl2=thisComp.layer("Ctrl2").transform.position;

    //Measurements
    oldDistance = initCtrl1-initCtrl2;
    newDistance = newCtrl1-newCtrl2;
    xRatio = newDistance[0]/oldDistance[0];
    yRatio = newDistance[1]/oldDistance[1];

    //Adds relative movement to the 0 value controller
    newPos=[newCtrl2[0]+objPos[0]*xRatio, newCtrl1[1]+objPos[1]*yRatio];

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy