Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Object not able to overlay another objects (or keeps distance with n pixels).

  • Object not able to overlay another objects (or keeps distance with n pixels).

    Posted by Long Nguyen on November 22, 2020 at 1:30 am

    Hi, I have these 2 dots here and I want to move the white dot freely around the comp, but it will never be able to overlay the red dot, or always stays away around 50 pixels or any editable amount of pixels from the red dot. What can I do?

    Long Nguyen replied 5 years, 8 months ago 2 Members · 2 Replies
  • 2 Replies
  • Frank Mansfield

    November 23, 2020 at 12:47 am

    Hi Long

    This is probably a question for the expressions forum. I have had a bash at this, but my solution is pretty clunky and amateurish (anything even approaching real maths is way above my expression pay-grade!).

    I’ve attached the test project I was playing with for you to have a look at, but basically I put this expression on the position property of the moving layer:

    distanceValue = 200;

    basePos = transform.position;

    otherDotPos = thisComp.layer(“Shape Layer 1”).transform.position;

    distanceBetween = length(basePos, otherDotPos);

    newVector = basePos – otherDotPos;

    newSetLengthVector = ( distanceValue / distanceBetween ) * newVector;

    if ( distanceBetween <= distanceValue) otherDotPos + newSetLengthVector; else basePos;

    the “distanceValue” is how far away it stays, and “otherDotPos” is the layer it’s staying away from.

    Still might be worth a shout to the expressions forum, as people who are actually good at this stuff could probably add some damping or something to stop it having the potential to jump around so much. But for goodness sake, don’t show them my code, I’m not sure I could take the shame… 😉

    Cheers!
    -f

  • Long Nguyen

    November 24, 2020 at 5:16 pm

    Haha really thank you so much for the help Frank!

    I just made another post at the expression forum about this to get more answers. If you like you can go check it out!

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