Skip to main content

Maya Expression Help: Motion Paths

I've built a fan using motion paths, but need to animate it using expressions to be able to control the speed and various other things. The fan animated with keyframes:



I'm trying to create an expression which makes each fan blade traverse the motion path like it does above, but the expression is only executed once. My expression at the moment:



Is there a way to have the expression execute itself again once the blade has made one revolution of the path? Once the uValue hits 1, it stays at 1. I think I need it to reset to 0 once it reaches 1 so that the blade appears to rotate indefinitely.

I took a shot in the dark and wrote this:

motionPath1.uValue = time * 0.1;
if (motionPath1.uValue ==1) motionPath1.uValue =0;

But it didn't work.

EDIT: Resolved using this code:

motionPath1.uValue = (frame % 60) / 60;

Where "60" is the number of frames the object takes to revolve fully around the motion path, or, if the motion path isn't closed, for the object to go from start to finish. It works by converting the current frame into a percentage, so frame 15 would make the uValue 0.25, frame 30 would make it 0.5, at 60 it is reset to 0, and frame 90 would make it 0.5, et cetera.

You can replace the number with an attribute value if you want to be able to control the speed without going in an editing the expression, of if you want to control multiple object's speed using just one attribute. For example:

motionPath1.uValue = (frame % Blade_Control.RotationSpeed) / Blade_Control.RotationSpeed;

Where 'Blade_Control" is the object and "RotationSpeed" is the attribute.

Comments

  1. Excellent ! A very useful way of controlling a motion pathed object speed.

    Thank you so much !!

    ReplyDelete

Post a Comment