Other conditional statement options
 
 
 

You can make Balloon rise after it inflates by adding another if statement to the expression.

To add an if statement to the expression

  1. Change the expression to this:
    if (time < 2)
    	Balloon.scaleY = time;
    if (time >= 2)
    	Balloon.translateY = time;
  2. Click Edit to compile the expression.
  3. Play the animation.

    Balloon inflates for two seconds. After two seconds, Balloon stops inflating and its position skips from a Y-axis position of 0 to 2. You’ll eliminate the motion skip in a later step.

    The new if statement increases the translateY position of Balloon after the animation time rises above two seconds. The >= symbols mean greater than or equal to. Whenever time is greater than or equal to 2, the expression assigns Balloon’s translateY the value of time. The translateY value therefore increases for the rest of your animation’s playback range.

    Notice that a semicolon ends each statement for a particular condition. Forgetting a semicolon after each statement causes a syntax error, and the changes you’ve made to the expression won’t take effect.

    NoteAlways examine the Script Editor for error messages after you edit an expression and click the Create button. If you alter a previously successful expression and a syntax error occurs, Maya executes the previous successful expression when you play the animation. This might make you believe your changes took effect. Error messages are preceded by the text // Error:.
  4. Stop the animation and go to the start time. Balloon flattens but doesn’t return to the origin. (If Balloon has risen out of view, adjust your camera to see it.)

    Balloon doesn’t return to the origin because the expression doesn’t assign Balloon a starting point for the beginning of the animation.

  5. To make Balloon return to the origin, change the expression to this:
    if (time < 2)
    	Balloon.translateY = 0;
    if (time < 2)
    	Balloon.scaleY = time;
    if (time >= 2)
    	Balloon.translateY = time;

    The new first statement sets Balloon.translateY to 0 whenever time is less than 2.

    Note that you can put the three statements in any order in this example. When Maya plays each frame, it executes each statement in the expression in the order listed. In this example, the statements work independently, so their order doesn’t matter.

    We put the statements in the order of time execution because it’s easier to see the logic of the expression. If you ever need to change the expression, you’ll be able to grasp the expression’s actions more quickly.

  6. Click Edit.
  7. Stop the animation and go to the start time.

    The flattened Balloon returns to its correct position at the origin.

  8. Play the animation.

    Balloon inflates for two seconds, then rises. As it rises, it jumps slightly higher at approximately frame 48.