Kranky

12 December 2010, 10:23 AM

Hi! 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.

( 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.