Hi Dan, hi all, and tanks again for your help!
Based on the expression you sent, I tried to go further, and extend it to a 9×9 grid go squares, with the element named “Target” wiggling all over it, so not one axis anymore.
As you can see with the attachment, it does work somehow, but most of the times the whole row gets triggered, and, weirdly, only a chuck of a horizontal or vertical row…
What I want to achieve now is, when approaching a square —let’s say when it is touching it (each saquer is 120×120 pixels, so once the target is nearing it by 60 pixels on X and Y), the square must spin 90} and retains that rotation value until they meet again and it can spin further.
Here is what I wrote (please don’t mind):
p = thisComp.layer("Target").position;
animateFrames = 15;
Hor = p.valueAtTime(0)[0] >= position[0];
Ver = p.valueAtTime(0)[1] >= position[1];
fCur = timeToFrames(time);
f = 1;
fSave = 0;
n = 0;
while (f <= fCur){
if (Ver){
if (p.valueAtTime(framesToTime(f))[1] < position[1] && p.valueAtTime(framesToTime(f))[0] < position[0]){
Hor = false;
Ver = false;
}
}else{
if (p.valueAtTime(framesToTime(f))[1] >= position[1] && p.valueAtTime(framesToTime(f))[0] >= position[0]){
n++;
Hor = true;
Ver = true;
fSave = f;
}
}
f++
}
r = 0;
if (n > 0){
r = (n-1)*90 + ease(fCur-fSave,0,animateFrames,0,90);
}
value + r