QUOTE(mattosbo @ 09/13/05, 03:18 AM)
Is there a way I can control the rotation of the wheels using expressions or MEL, by calculating the ACTUAL distance travelled, possibly by using a motion path?
[snapback]214771[/snapback]
Hi,
If you have a motion path you ought to be able to use an arcLength node to get the distance down the path. However if the path does not describe the wheel motion but a "center of vehicle" motion, it might not be as exact as you need (wheels spin out of sync with movement).
Another approach to the problem is to use a "cyclic" update of the roatate attribute. Basically an expression like this:
CODE
float $increment = 10;
wheel.rotateX = wheel.rotateX + $increment;
Each time this expression evaluates, it will increase the angle by the $increase amount. You might get cycle-warnings from this, but they can be turned off by cycleCheck -e off. I believe that you will need to set the expression as "always evaluate", but you can play around with this.
The downside of this expression is that if you play the animation backwards, the wheels will still rotate forwards, but that is a small inconvenience since it can be baked before rendertime for instance.
Then you can refine this expression by fine-tuning the $increment value. Increment angle can for instance be related to distance travelled by taking in consideration that the distance travelled by one complete turn is equal to the circumference of the wheel:
angle / 360 = distance / circumference
...which gives:
angle = distance * 360 / circumference
Distance travelled can be calculated by the following expression on some object moving in worldSpace (for instance a pointConstrained object tracking the wheel motion)
CODE
float $old[] = getAttr -t (frame - 1) trackingObject.translation
;
float $dx = trackingObject.translateX - $old[0];
float $dy = trackingObject.translateY - $old[1];
float $dz = trackingObject.translateZ - $old[2];
float $distance = sqrt($dx*$dx + $dy*$dy + $dz*$dz);
(this code uses one expensive MEL call, but I do not know of any other method to get last frame's value).
etc. etc. this can be further refined of course if the vehicle should go both forwards and backwards, but anyway - I think you get the general idea.
Good luck
Best regards
/ Daniel