I figured out the correct expression myself.
First, I set up a null with an expression controls Slider Control “check distance” (just to do some of the calculations).
There, I calculated the distance:
var posA = thisComp.layer(“Shape A”).transform.position;
var posB = thisComp.layer(“Shape B”).transform.position;
var distance = length(posA, posB);
distance
On another slider, I set up the frame expression:
var distance = effect(“check distance”)(“Slider”);
var compLength = thisComp.duration / thisComp.frameDuration;
for (i = 0; i <= compLength; i++) {
if (distance.valueAtTime(framesToTime(i+1)) >= distance.valueAtTime(framesToTime(i))) break
}
i
I would have liked to put all the expressions onto a single slider. However, when I insert length(posA, posB).valueAtTime(framesToTime(i) into the expression, I get an error: This is not a function.
Is there a way to get around this error?