View Full Version : Rotating Wheel Expression Problem

 Kranky12 December 2010, 10:23 AMHi! Im quite new to mel-scripting and recently i tried to create this expression that i learned from a tutorial. The expressions function is to rotate a wheel, and where ever it is rotated it will keep its rotation. But somewere in the script there seems to be some problems, because all i get is syntax error. ( link to the tutorial; http://www.youtube.com/watch?v=f33ar9gy2UY&feature=related ) Here's the script: global float \$oldX = 0.0; global float \$oldZ = 0.0; \$radius = 0.089; \$distance = 0.0; \$flip = 1; if (\$oldX == 0.0 44 \$oldZ == 0.0) driven.rotateX 0.0; else ( //The control_handle is the node that drives the wheel forward. \$change_X = control_handle.translateX - \$oldX; \$change_Z = control_handle.translateZ - \$oldZ; \$distance = sqrt ((\$change_X * \$change_X) + (\$change_Z * \$change_Z)) ; \$cur_angle = control_handle.rotateY % 360; if (\$change_Z < 0) \$flip = -1; if (\$cur_angle > 90) \$flip = -1 * \$flip; if (\$cur_angle >= 270) \$flip = -1 * \$flip; if (\$cur_angle < -90) \$flip = -1 * \$flip; if (\$cur_angle <= -270) \$flip = -1 * \$flip; //driven is the wheel itself driven.rotateX = driven.rotateX + (\$flip = ((\$distance / (6.28 * \$radius)) * 360.0)); ) \$oldX = control_handle.translateX; \$oldZ = control_handle.translateZ; Here's what it says in the Script Editor // Error: if (\$oldX == 0.0 44 \$oldZ == 0.0) // // Error: Syntax error // // Error: else // // Error: Syntax error // // Error: \$distance = sqrt ((\$change_X * \$change_X) + (\$change_Z * \$change_Z)) ; // // Error: "\$change_X" is an undeclared variable. // // Error: \$distance = sqrt ((\$change_X * \$change_X) + (\$change_Z * \$change_Z)) ; // // Error: "\$change_X" is an undeclared variable. // // Error: ) // // Error: Syntax error // I hope that someone could help me figure out this problem.
Sebek128
12 December 2010, 11:04 AM
if (\$oldX == 0.0 44 \$oldZ == 0.0)

There is && instead 44, it means AND between conditions.

else
(
code....
....
..
)

There should be curvy brackets instead round {}

"\$change_X" is an undeclared variable. //

This is propably because of this wrong brackets.

rahulsg2901
12 December 2010, 11:20 AM
chk out ths

global float \$oldX = 0.0;
global float \$oldZ = 0.0;
float \$distance = 0.0;
float \$flip = 1;
if (\$oldX == 0.0 && \$oldZ == 0.0)
{
driven.rotateX = 0.0;
}
else
{
//The control_handle is the node that drives the wheel forward.
float \$change_X = control_handle.translateX - \$oldX;
float \$change_Z = control_handle.translateZ - \$oldZ;
float \$distance = sqrt ((\$change_X * \$change_X) + (\$change_Z * \$change_Z)) ;
float \$cur_angle = control_handle.rotateY % 360;
if (\$change_Z < 0)
\$flip = -1;
if (\$cur_angle > 90)
\$flip = -1 * \$flip;
if (\$cur_angle >= 270)
\$flip = -1 * \$flip;
if (\$cur_angle < -90)
\$flip = -1 * \$flip;
if (\$cur_angle <= -270)
\$flip = -1 * \$flip;
//driven is the wheel itself
\$flip = ((\$distance / (6.28 * \$radius)) * 360.0);
driven.rotateX = driven.rotateX + \$flip;
}
\$oldX = control_handle.translateX;
\$oldZ = control_handle.translateZ;

changes make in red

Kranky
12 December 2010, 11:36 AM
Thanks for the help! But now i have run into further problems.

I used your fixed script rahulsg2901 (http://forums.cgsociety.org/member.php?u=344920).

I have point constrained the wheel to a locator wich is parented to the car axel. The problem now is that when i turn the axel the wheels does not rotate with the axel, they keep staying in the same y-rotation as always (But the x/z rotation works). Were in the script does this problem occur?

EDIT:
Problem solved by using both a orient and point constraint. Thank you for the help!

CGTalk Moderation
12 December 2010, 11:36 AM
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.

1