Notifications
Clear all

[Closed] Convert Mel expression to Maxscript – Help

Hi guys

can anyone help me convert this MEL expression to Maxscript?

float $fRot=car.translateX*-360;
float $fFreq= frame;

left_front_wheel.rotateZ=$fRot;
left_back_wheel.rotateZ=$fRot;
right_front_wheel.rotateZ=$fRot;
right_back_wheel.rotateZ=$fRot;

I have it working in Maya, whereby if move the car object it makes the wheels rotate – with accurate surface contact and distance (no sliding tire problem)

I am trying to do the same thing in Max

6 Replies

Okay VERY basic conversion. Two issues exist. 1 – I don’t have the mel docs avaliable to me right now and 2 – I don’t know any way to calculate the translation of an object in max without referencing the keyframes and manually calculating the movement…this is not shown here as I’m guessing that the “translatex” method is holding the movement bewteen frames for maya.


 (
   -- Need to calculate the distance travelled, typically between key frames
 
   local fRot= distanceTravelled * -360;
   local $fFreq= currentTime.frame;
   
   $left_front_wheel.rotate.Z=fRot;
   $left_back_wheel.rotate.Z=fRot;
   $right_front_wheel.rotate.Z=fRot;
   $right_back_wheel.rotate.Z=fRot;
 )
 

remove the ;

 PEN

The “;” doesn’t actualy matter and can be used in Max Script.

The current Maya expression will run into the same problems that you would see in Max if you went about it the same way. All that he is doing is getting the position of the object and rotating the wheels based on that.

What is $fFreq supposed to be doing in your expression in Maya?

Also in Max $.rotation.z will return the z portion of a quat value, what you are after is the z axis of an eulerAngle. You will need to use $.rotation.Z_rotation instead. This is assuming that you have the default euler_XYZ controller on the rotation.

Using the stright position value of the car to rotate the wheels will run into a couple of problems. One you will have to add together all three of the position axes or the car will not be able to move on any other axis other then the one that is used, in this case it was X. Also if the car turns 180 deg and drives forward the wheels will rotate backwards because the car doesn’t know that it has turned around, it just knows that it is now moving in a negative direction.

Using a distance travelled method you will have to sample time using something like.
p1= at time currentTime $.pos
p2=at time (currentTime-1) $.pos
vec=p2-p1 or dist=distance p1 p2 depending on what you want to start with.

1 Reply
(@dutch_delight)
Joined: 11 months ago

Posts: 0

Never even realised.
Just when you think you know it all…you learn something new.

Mental note, don’t code when you are half asleep

The original scripting is attempting to calculate/animate the number of times wheels on a car need to turn based on the distance the car has travelled over time…I saw the original script briefly a few days ago, can’t remember where, just recall that section of it.

I’m also guessing the $fFreq is either the number of frames travelled, so we can calculate [font=Arial]accurately the number of times the wheels spine based on their circumference or the current frame.

Would you also recommend applying the rotation in coordsys local…to ensure that the wheels rotate about the local axis??
[/font]

 PEN

Using coordsys local will not help you. Just applying the script controller to the correct axis in an euler XYZ controller will do the trick. Make sure that you freeze the transform of the controller first and use the second controller in the list as the one that drives the wheels.

The problems that I was pointing out about what axis the car is traveling on will not be afffected by using coordsys.

I should also mention that if you are using the distance traveled method you are now going to run into another problem. If you set it up so the wheel rotates forward when the car travels a given distance the car will not know if it is traveling froward or backward, it just knows that it moved a given distance. You will then have to set up a method for determining what direction it is moving. This can be done in a few ways. I saw one person fire rays at a plane that was linked to the car and the direction of the ray was the vector retured from p1 and p2. If it hit the plane it was traveling backwards. Crazy method but it worked great. The best way is to use the dot product of two vectors as that can be used as a multiplier for the rotation of the wheels.