An expression like below works, but it can be slow to compute (has to iterate over every past frame)
I’ve tweaked the curviness determination function such that it looks 8 times further forwards than backwards, this mimics a race driver: going slower into a curve, but accelerating as soon as the curve is behind us.
the Math.pow( ,0.2) is also arbitrary: it slopes the difference between 0 curviness and 1 curviness by a power of 1/5, sort of like a gamma.
<pre class=””>
p=thisComp.layer(“Shape Layer 1”).content(“Shape 1”).content(“Path 1”).path;
function curviness(path, pos_on_path, width, samples) {
var c = 0;
for (i=0; i<=width/2; i+=width/samples/2) {
c+=length(
p.normalOnPath((1+pos_on_path-i/8)%1),
p.normalOnPath((pos_on_path+i)%1)
);
}
return Math.pow(c/samples/2,0.2);
}
// speeds in percentage of path per second.
minSpeed = 2;
maxSpeed = 50;
travel = 0;
for (t=0; t<time; t+=thisComp.frameDuration) {
curve = curviness(p, travel, 0.06, 8);
travel+=linear(curve, 0, 1, maxSpeed, minSpeed)/100*thisComp.frameDuration;
}
travel%=1;
thisComp.layer(“Shape Layer 1”).toComp(p.pointOnPath(travel));