Skip to main content

Maya Expression Help

I've set up controls for a vehicle's wheel speed by creating an expression, but it doesn't work exactly how it needs to. On keying 0 to ##, the wheels speed up as they should, but on keying ## to 0, they reverse their direction instead of slowing down to a stop. I can sort of understand why this is happening, but I can't think of a fix.

Example, where the speed is keyed like so: 0 - 50 - 50 - 0


This is my expression.

Rear_Rim_1.rotateX = (time * Wheel_Speed_Control.RearWheelSpeed);
Rear_Rim_2.rotateX = (time * Wheel_Speed_Control.RearWheelSpeed);
Front_Rim_1.rotateX = (time * Wheel_Speed_Control.FrontWheelSpeed);
Front_Rim_2.rotateX = (time * Wheel_Speed_Control.FrontWheelSpeed);

Does anyone have any idea how I should rewrite the expression?

Comments

  1. Hi Simon

    First things first, you are going to need a few variables. (and this script is probably just one of many ways of achieving the effect.)

    I've commented the script so it will be easier to read in another editor.

    //Create variables
    int $currentTime = `currentTime -q`; // creates a variable that is equaling the current frame number
    if ($currentTime <= 1) {float $myRotation = 0; } // creates a variable to hold a rotation value (this gets plugged into the wheels rotation). The IF statement checks to see if you are on frame 1, and will reset it to 0 if that is the case
    float $speed = speedLoc.speed; // creates a variable to hold the speed attribute
    float $currentRotation = wheel.rotateZ; // a variable that holds the current rotation of the wheel

    // The calcualtion
    $myRotation = $currentRotation + $speed; // So I want my rotation value to equal the current value of the wheel's rotation, plus the speed.
    // this way the rotational value will never reverse unless the speed is put into minus values.

    //Connecting the output value to the wheels rotation
    wheel.rotateZ = $myRotation;


    and thats it.
    So without all my cluttered comments, just replace the stuff in caps.
    You will probably want to alter the variable names to something more descriptive too.

    int $currentTime = `currentTime -q`;
    if ($currentTime <= 1) {float $myRotation = 0; }
    float $speed = THE_SPEED_ATTRIBUTE;
    float $currentRotation = THE_WHEELS_ROTATION_ATTRIBUTE;

    $myRotation = $currentRotation + $speed;

    THE_WHEELS_ROTATION_ATTRIBUTE = $myRotation;


    I hope this is useful to you

    Ethan

    ReplyDelete
  2. ps - you may need to divide the whole calculation, as the speed is quite sensitive!

    ReplyDelete
  3. ps - actually you only want to divide the speed variable if it is too sensitive.

    ReplyDelete
  4. Thanks Ethan, I didn't expect feedback so soon, and so detailed. Thanks again!

    ReplyDelete
  5. No problem. I just got back from holiday yesterday, and was missing Maya!

    actually I have just found there is still one slight problem with the script, in that I've attempted to make it reset the value back to zero when on frame 1. It doesn't seem to work in the current setup. In the mean time, the only way it you can resent the value is to disconnect the wheels rotation from the script, reset the value, and reconnect it.

    not much of an issue though... Although when rendering, bake the animation on the wheels or you may encounter some offset between renders as the wheels default position doesn't automatically reset.

    ReplyDelete

Post a Comment