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