If you or anybody else is interested, I have a different method:
it’s posted on my site, and I’ll post it here in case there are questions:
Link
global vector $oldPos;
global float $oldDistance;
float $Pi = 3.14159265;
float $r = 5; //Radius
float $circumference = (2*$Pi*$r);
int $gear = -1;// -1 for reverse +1 for Forwards
if (frame==0) {
$oldPos=<<0,0,0>>;
$oldDistance = 0;
}
float $old[] = $oldPos;
float $dx = pSphere1.translateX - $old[0];
float $dy = pSphere1.translateY - $old[1];
float $dz = pSphere1.translateZ - $old[2];
float $distance = sqrt($dx*$dx + $dy*$dy + $dz*$dz);
print $distance;
if (frame==0) $distance = 0;
float $newDistance = $distance+$oldDistance;
pSphere1.rotateZ = $gear*($newDistance / $circumference)*360;
$oldDistance = $newDistance;
$oldPos=<<pSphere1.translateX,
pSphere1.translateY,
pSphere1.translateZ>>;
so what this does, is calculate the distance of an object’s translation, which you need to feed in in world space, so maybe point constrain a locator to the axle, and then connect the translations into the expression, also you’d do better connecting multiple wheels going in the same direction to one expression, rather than copying it, since it has global variables, and needs to keep them separate per expression.
A couple of shortcomings:
1)It’s an expression, and therefore not that “real time”, it calculates (a positive) distance in both fwd, and backwards directions. You could animate the gear value or hook it into an animateable value if you needed to go back and forth.
2)You need to correctly measure the Radius and enter it into the expression. 3)It doesn’t know if you’re on a hill, so this only works on flat ground. On inclines you’ll get slipping of the wheel.
On the Plus side, you can go positive negative, across whatever axis’s 0 point, you want it won’t screw up, unlike other methods that calculate only along one axis… and have issues with crossing positive to negative Cartesian coordinates.
I am working on a wheel “node” that will run in real time, but it’s a bit out from release… It has all of the shortcomings from above fixed though, so good progress !