PDA

View Full Version : Monocycle Wheel Problem. Attempting to get translate to follow rotate axis.


MaxT2K
01-30-2009, 10:39 AM
Hi everyone,

I've recently started my own series of animations and have a character that rides a monocycle through some obstacles and came up with the seemingly brilliant idea of writing a Mel code that would automatically turn the wheel as the monocycle move.

I wrote this script pretty quickly and based the original means of measurement on monocycles controller's Z translate. I knew that this would be dependent on world space so the program would not work in all directions but it at least moved realistically back and forth.

Here is the code... (Note that I added new attributes 'WheelStop' to the control and 'PreWheelRotate1' (which rotates the wheel's begining position) and 'WheelSpeed' (Set at 37) to the wheel.)

------

float $oldtranslate;
float $Wprerotate;

if (MonocycleCtrl1.WheelStop < 1) {
Wheel1.rotateX+=((MonocycleCtrl1.translateZ-$oldtranslate)*Wheel1.WheelSpeed)+(Wheel1.PreWheelRotate1-$Wprerotate);
};

$oldtranslate=MonocycleCtrl1.translateZ;
$Wprerotate=Wheel1.PreWheelRotate1;

------

The trouble is that if you turn the monocycle 90 degrees the wheel doesn't rotate at all when you move it. I had hoped to find a way after this to get a consistant messurement such as finding a node for local translate, rotating the translates or even a combination of Parenting and Constraining to make translate Z follow.

You can put the object in a group and turn that at the start but if you want to turn it again it slides the wrong way.

I've looked everywhere to find some answer but to no success so if you can help it would be very much appreciated.

Thank you.

Max

YourDaftPunk
01-30-2009, 11:41 PM
Ok, I've attached a scene with two wheels. One is driven by expressions, the other by utility nodes and is attached to an animation path.


Notice that even with the animation path setup (my preferred version) you can adjust the motionPath1's uValue and get real time feedback on the rotation. Try grabbing a cv on the animation path and dragging it up to make a hill; the wheel will follow nicely with the correct amount of rotation.

It's setup so that the animation path curve feeds into an arcLengthDimension node. arcLengthDimension can calculate the length of a curve (or a portion of a curve). The motionPath node is also connected to the arcLengthDimension- the wheel's current uValue (which is really its position on the curve) is plugged into the arcLengthDimension.uParamValue. This means that arcLengthDim is calculating the distance from the start of the curve to the current wheel position on the curve.

The distance is then passed into a couple of multiply divide nodes which are using the formula:
distanced_travel / (pi * 2 * wheel_radius) * degrees

Graph the network to see what I'm talking about.


The expression version is calculating the distance traveled by finding the magnitude of a vector between the last position and the current position. It then uses the same formula to add rotation to the wheel. Notice that at the end of the expression, I'm storing the current position to custom attributes I created on the wheel- this means that next frame I'll have access to both the current position and the last position to find the vector. Another approach is to make the wheel a passive rigid body- the rigid body node will let you access things like velocity and lastPosition.


I hope this gives you some ideas; there are many ways to do it. There are also scripts on highend3d if you need more resources.

-shawn

edit: There was a problem with the arclen node, I just recreated the node and uploaded the file.

MaxT2K
01-31-2009, 10:40 AM
Hi Shawn,

Thank you so much, you're an absolute life saver!

Both the curve path and the expression method are going to be extremely useful in my animation. I had attempted to write something similar to the expression version but I couldn't get it to work in all directions. There are a couple other scenes that I think I could use these for so now I'm looking forward to learn how they work.

Cheers,

Max

vvkonline
01-31-2009, 08:56 PM
hi Shawn,

it looks like arc length is always at zero that you feed in to MD "div_distance_by_circumference"

so wheel is not spinning in the example with the nodes.

YourDaftPunk
02-01-2009, 01:32 AM
Thanks Vadim, I fixed it and re-uploaded the file to my original post. All I did was remake the arclength node, and it was fine. I must have made a change that broke the node and resaved without testing, so thanks for the heads up.

-shawn

vvkonline
02-01-2009, 01:43 AM
cool, thanks for sharing by the way, was looking for a way to do this without expressions.

edit:
also i was wondering how U is not from 0 to 1

YourDaftPunk
02-01-2009, 02:46 AM
When you build a curve, the U value is equal to the number of spans. You can always run Rebuild Curve to rebuild it as a uniform curve from 0-1.

vvkonline
02-01-2009, 03:35 PM
ah I see
thanks

MaxT2K
02-02-2009, 09:04 AM
Ah, I see. I noticed as well that curve wheel wasn't spinning but I thought that it could be because I'm using an earlier version of Maya. I solved this by using a simple expression but thanks for fixing it Shawn.

And thanks vvkonline for helping out.

Max

CGTalk Moderation
02-02-2009, 09:04 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.