PDA

View Full Version : Dynamic Car Rig


andy101
07-21-2005, 11:36 PM
Hi guys,

After looking at the dynamic Ferrari Car posted here:
http://forums.cgsociety.org/showthread.php?t=194356

by roni, i wanted to make something similar for my own animation. I am actually using a Ferrari Modena as well =D.

Below i have cut-and-pasted the script that i have written with reference to Roni's, and, after editing the Syntax errors in it via the script editor, it does not seem to work as it should in maya.

I used just one tire to test the script, and keyframed the 1st and 500th frame to different translate keys. Frame one being (0,0,0) and frame 500 being about (90, 0, 80), in format (x,y,z).

I plugged in the script, and saw that the wheel, while rotating at about the speed that it should be, rotated on the wrong axis, and looked like it was flipping head over heels instead of being tire-like.

Here is the script:

Note: if a word has "<>" around it, that means that it will be replaced with the name/value of real thing once they are created.

float $transX = <leftwheelname>.translateX;
float $transZ = <leftwheelname>.translateZ;
float $tls = 'currentTime-q' - 1;
float $lsx = 'getAttr -time $tls <leftwheelname>.translateX';
float $lsz = 'getAttr -time $tls <leftwheelname>.translateZ';
float $relx = $transX - $lsx;
float $relZ = $transZ - $lsz;
float $hyp = sqrt(($relx*$relx) + ($relz*$relz));
float $wheelaim = asind($relx/$hyp);

//Scripting various rotation of the wheel.
//Required: An (empty) node named "CarVars"

//Turning wheels to correspond to aim of car.

if (carvars.backwards == 0)
{
if ($relx <= 0 && $relz > 0 || $relx > 0 && $relz > 0)
{
<leftwheelname>.rotateY = 90 - $wheelaim;
}
else
{
<leftwheelname>.rotateY = 90 + $wheelaim;
}
}
else
{
if (carvars.backwards == 1)
{
if ($relx <= 0 $$ relz > 0 || $relx > 0 && $relz > 0)
{
<leftwheelname>.rotateY = -90 - $wheelaim;
else
{
<leftwheelname>.rotateY = -90 + $wheelaim;
}
}
}

//Turning wheels to correspond to their rotation as they spin on the ground.

if (carvars.backwards == 0)
{
<leftwheelname>.rotateX = <leftwheelname>.rotateX + $hyp*360/(2*3.14159*<wheelradius>);
}
else
{
if (carvars.backwards == 1)
{
<leftwheelname>.rotateX = <leftwheelname>.rotateX - $hyp*360(2*3.14159*<wheelradius>);
}
}

<leftwheelname>.rotateX = <leftwheelname>.rotateX;



The carvars.backwards attribute specifies if the car is moving backwards or forwards (i.e. if it is in drive or in reverse).

I would be happy and gracious beyond belief if somebody could help me with this. This is one of my first lengthy MEL/expression projects, and I really do not want it to become a nightmare =D.

Thanks greatly in advance to any replies.
-Andy

CGTalk Moderation
07-21-2005, 11:36 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.