View Full Version : Wheel Roll Expression
Genesis 05032006, 06:14 AM Hey Guys,
I am kind of stuck with my wheel roll expression, and pretty new to Maya... Right now I have:
float $increment = 3.14*4;
float $disx = locator1.translateX;
float $disy = locator1.translateY;
float $disz = locator1.translateZ;
float $distance = sqrt($disx*$disx + $disy*$disy + $disz*$disz);
if ($distance > 0)
pCylinder1.rotateZ = pCylinder1.rotateZ + $increment;
if ($distance < 0)
pCylinder1.rotateZ = pCylinder1.rotateZ  $increment;
print($distance);
With the pCylinder1.rotateZ being driven by locator1.
But it always rolls the one way? If I change the top 'if' statement from positive to negative $increment I can change it's roll from forward to backwards, but I can't get it to change depending on weather the move is positive or negative?
Any help, or errors you might notice would be great. I want the wheel to just rotate as the locator moves.
*the print was just so I could see the value.
Thanks,


A_New_Hope
05032006, 06:37 PM
looks like the distance value alwas is bigger then 0
so the if ($distance < 0) will never be run :(
Stucky
05032006, 06:58 PM
Genesis. I use a much more simple expression:
float $radius = 2.6;
float $pi = 3.1416;
wheel.rotateX = 360*(group1.translateZ/(2*$pi*$radius));
wheel.rotateX is refering to the group of the wheel.
group1.translateZ is refering to the car group that the wheels are attatched to. In you case is the locator. And in my case where X axis for the rotate wheel and Z for the translation. It can be different to you. Just this one out if you want...
and the radius variable, is actually the radius of the wheel. You have to measure it.
Hope it helped...
S
Genesis
05032006, 11:11 PM
Stucky, that worked well, thanks! The wheel now rolls forward and back, I have a new issue now however.
When the translations move into the negative areas of the Cartesian plane, I get a strange rotation flip as it reaches 0, then it works backwards in negative translations... Have I missed something? Is there any way this can be fixed?
I now have:
float $radius = 1;
float $pi = 3.1416;
float $disx = locator1.translateX;
float $disy = locator1.translateY;
float $disz = locator1.translateZ;
float $distance = sqrt($disx*$disx + $disy*$disy + $disz*$disz);
pCylinder1.rotateZ = 360*($distance/(2*$pi*$radius));
Thanks again, you rock.
csc2h
05032006, 11:21 PM
An even easier way to do it WITHOUT mel if this is what you are trying to accomplish is with Set Driven Key, and then to have it repeat go into the graph editor and set the SDK curves to infinity and repeat how you want  im not sure of the results you want but it can yield some very fast results if you want a basic wheel turn with a translate or something.....just an idea...
Stucky
05042006, 10:17 AM
Genesis: Humm, with me it worked ok. I think the problem is with you distance variable. Can't you use only one value?!? say, translateZ?!?! Do you need to use the 3 axis? If you can't use only one value axis, try to multiply by 360(negative 360) instead of 360, when you are in the negative cartesian part. If this works, you have to some how find a way to tell it that when it is in the negative part it uses "360", when it is positive it uses "360". ATTENTION: I'm NOT sure if what I'm saying works...
csc2h: In fact what you said does not work because the wheel would have the same rotation whether the "car" is moving fast or slow. And with the expression I mentioned, when the "car" moves slower, the rotation of the wheel is slower too, accordingly to the "car" speed.
EDIT: I remembered on other thing. If the problem is really the negative values that you get when you are in the negative part of the quadrants, instead of changing the "360" to "360"(and I think this woulndt solve the problem), you could try to always get the absolute(positive) value of your $distance variable. something like:
float $distance = abs(sqrt($disx*$disx + $disy*$disy + $disz*$disz));
abs() function is to get the positive value. If you run abs(10); it will return 10. Try this one out and see if it solves your problem.
S
Robert Bateman
05042006, 12:45 PM
uhm, sqrt only ever returns positive numbers, hence the flip when wandering back into the negative cartesian space ;) I'm afraid you can't simply use a distance from the origin to determine rotation of the wheel.
The car (or whatever) should have a reference for which direction is forward. Then the change in translation of the wheel should have a direction vector (which will mean storing the previous frames translation). If you dot product the cars forward vector with the translational change vector, you will get a +ve or ve number. If +ve, add to the rotation, if ve subtract from the rotation.
Stucky
05042006, 01:03 PM
Yes Robert that was what I said. I think Genesis should use only translateZ(the forward direction) of the "car". He doesnt need the 3 axis values.
S
Robert Bateman
05042006, 01:42 PM
uhm,
float $distance = abs(sqrt($disx*$disx + $disy*$disy + $disz*$disz));
abs() function is to get the positive value. If you run abs(10); it will return 10. Try this one out and see if it solves your problem.
just pointing out that abs( sqrt() ) has no effect since sqrt always returns a +ve number....
Stucky
05042006, 01:55 PM
ok robert, thanks. I didnt know that too. But Genesis shouldnt even use that. it get to complicated, and it can be much simpler...
Thanks Robert...with you we always learn...
S
Robert Bateman
05042006, 02:46 PM
yeah, i know how to solve this one, got some work to do at the moment though. yeah, distance from the origin doesn't tell you much about the relative rotation of the wheel (since you could skid at 90 degrees to the wheel, and you wouldn't expect it to rotate).
Thats the one issue with sqrt, 2*2 == 4, 2*2 == 4, sqrt just returns the +ve value. You always have to assume that sqrt() is also a valid answer....
But basically, distance/length are scalar quantity (have no direction), therefore you need to use vector quantities since they consider direction of movement to be important
Stucky
05042006, 02:53 PM
lets see if Genesis can manage to implement our help to solve his problem. :)
S
Genesis
05042006, 10:48 PM
You guys are awesome :) thanks heaps.
I have had another quick project come in which I have to jump on, but on monday I will be back on the car, and I will fill you in on how it goes. Thanks again, I cant wait to have another play!
CGTalk Moderation
05042006, 10:48 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.
vBulletin v3.0.5, Copyright ©20002015, Jelsoft Enterprises Ltd.