I think you’re on the right track, except that the time remapping part has to figure out how long the animation has been moving in the current direction. I haven’t tested any of this (so there may be typos), but here’s how I’d do the slider:
v = position.velocity;
if (v[0] == 0 && v[1] == 0){
n = 0;
}else{
a = radiansToDegrees(Math.atan2(v[1],v[0])) + 180;
if (a < 22.5){
n = 3;
}else if (a < 67.5){
n = 5;
}else if (a < 112.5){
n = 1;
}else if (a < 157.5){
n = 6;
}else if (a < 202.5){
n = 4;
}else if (a < 247.5){
n = 8;
}else if (a < 292.5){
n = 2;
}else if (a < 337.5){
n = 7;
}else{
n = 3;
}
}
n
And here’s an attempt at the time remapping:
s = effect("Direction")("Slider");
timeMap = [0, 1, 2, 3, 4, 5, 6, 7, 8];
n = Math.round(s.value);
f = timeToFrames(time-thisComp.frameDuration);
while (f >= 0 ){
nPrev = s.valueAtTime(framesToTime(f));
if (nPrev != n) break;
f--;
}
t = time - framesToTime(f+1);
timeMap[n] + t;