Car Wheel Expression

so ive seen it posted here before but nothing has given me a clear answer
obviously im trying to make an expression to make a car tire rotate based on the distance traveled

currently im using an expression like this
wheel.rotateAxisX = 360 / (2*pi*r) * car.translateZ

the problem im having is that once the car is rotated 90 degrees in Y the expression no longer works, what i need is a way to get the cars object based translate, not world space translate, ive tried using xform -q -os -t and what not but with no results, so anyone got any ideas?

You can't hook it up to xform -q -os -t z value?

i tried loading the object space translates into an array and used $array[2] for the Z and it just didnt work, it would give me fluctuating from negative to positive and i was only moving in one direction

so the short answer is that it didnt work

This is a much more convoluted problem than it initially seems. It goes very deep into why it works fine in a game enigenie and not in animation one.

If we sidestep all the issues with neither local space nor world space movement being enough except for the last local step and even so only if each previous step was taken. And all the havoc you can cause maya with this.

See what you are after is NOT a local space movement but rather the full world space movement PATH over time. To get this you must be making some concession to maya. You will need to sacrifice some measure of feedback, accuracy, refresh speed or freedom of animation to get this working, like you want.

Your options are discrete simulation, this will work and give you best possible freedom of movement. However on the downside you totally loose the ability to scrub/jump in the time line and wheels reflecting it (its a drwaback of simulation). What you do is you use a incrementing expression instead of a determined one. And you calculate the direction of trave per frame l dot wheel axis for the increment ion amount, the bonus is you can get the wheels to bejhave very well and even simulate such things as springs etc. Direction can eb a bit tricky to spot but vector calculus provides a way to deal with this. If you ignore the wheels and bake the solution out evety time you need feedback its a reltively workkable solution.

Path anim. Paths do know their length. So if you bind the car to path anim you can KNOW the distance traveled. Offcourse you loose quite a measure of control in the process and need to work in different ways. Its very good for measuring speed and autoturning wheels too.

Integrate the curves, this is tricky. Its VERY VERY slow to do in expressions and mel. And quite involved maths in api side but tis does provide you with the ultimate tool. Whikle your at it make a derivation function too. It sacrifices some efficiency.

Pick thy poison.

I am not sure if the following will be helpful to you, but you can try this:

CODE
float $distance = 0.0;
vector $state[];

if (frame == 0) clear ($state);

int $a = (frame%100);        //this number sets the size of you array
int $b = (frame%100)+1;

$state[$b] = <>;     //you could use xform I guess
$rotation = mag($state[$b] - $state[$a]);   //magnitude of the difference vector

if ($a == 0)
$distance = ($state[$b] - $state[100]);

wheel.rotateAxisX = 360 / (2*pi*r) * $distance;

I did not have time to actually try this, but used something similar while ago for rotations and it worked just fine.