Basic Expressions Example

Making a Bouncing Ball

1. Choose Get > Primitive > Polygon Mesh > Soccer Ball. You could also create any type of sphere or ball as you like.

You will put an expression on the soccer ball’s Position Y parameter to control its up-and-down movement.

2. In the explorer, activate the All+Animatable Parameters filter. Then expand the soccer ball’s Local Transform properties, right-click on the Position Y parameter or its animation icon, and choose Set Expression.

Image:Expr3.jpg


The expression editor opens with the PosY parameter already loaded. You will apply a sinus function.

3. In the editing pane in the expressions editor, replace the existing 0.0 with sin( ( Fc * 4 ) * 4 )

Fc stands for "current frame", so the formulat will be recalculated at each frame.

4. Click Validate and then Apply. If no errors are found, the expression is added to the parameter.

Click the Play button to check the animation. The ball is moving up and down a bit. Not quite what you want, but at least the ball is moving.

5. In the expression editor, choose View > Show Graph or press Ctrl+g. Now you can see the function curve of your formula. As you can see, the cuve is also going into negative values.

6. To make sure that the ball just hits the ground and then jumps up again, change the formula to:

abs( sin( ( Fc * 4 ) * 7 ) ) 

The abs (absolute) statement changes every negative value into the equivalent positive value — always handy for cases like this where you don't want negative values. Now check what the graph looks like.

Image:Expr5.jpg


Play the animation again to see how it looks. The ball is jumping and hitting the floor. Now it would be great if you could easily control how high the ball is jumping. Well, you can by adding a custom parameter.

7. From the Animation toolbar, choose Create > Parameter > New Custom Parameter Set, and name the set Force. If you check in the explorer under the soccerball’s node, you’ll see a square orange “C” icon which is the custom parameter set.

8. To create a custom parameter in this set, choose Create > Parameter > New Custom Parameter. In its property editor, name it Height, set the default value to 7, and set the Value Range - Minimum to 4 and the Maximum to 30. Click OK.

9. In the expression editor, replace the 7 with the name of the new custom parameter that represents the ball’s height (Y position) so that it looks like this:

abs( sin( Fc * 4 ) * SoccerBall.Force.height )

Apply the expression and click play with looping on.

In the custom parameter set, drag the Height slider back and forth to see that you can control how high the ball is jumping. The ball is jumping pretty slowly and might not look like a heavy basketball or soccer ball.

Now you will create a second custom parameter so that you can control the speed at which it bounces, which gives the illusion of weight.

10. Select the Force custom parameter set in the explorer and choose Create > Parameter > New Custom Parameter.

In its property editor, name it Speed, set the default value to 8, and set the Value Range - Minimum to 1 and the Maximum to 30. Click OK.

11. In the expression editor, replace the 4 with the name of the new custom parameter that represents the ball’s speed so that it looks like this:

abs(sin( Fc * SoccerBall.Force.speed ) * SoccerBall.Force.height )

Apply the expression and play the animation while dragging the two custom sliders.

Image:Expr10.jpg


Although it’s moving up and down, you’ll notice that the ball is not yet moving forward. You’ll add an expression to the soccer ball’s Position Z parameter to remedy this.

12. In the explorer, right-click on the soccer ball’s Position Z parameter or its animation icon and choose Set Expression.

In the expression editor, replace the 0.0 with the formula Fc * 0.2 and apply the expression. The ball is now constantly moving forwards.

Now you will create a third custom parameter to control the distance the ball is moving.

13. Select the Force custom parameter set in the explorer and choose Create > Parameter > New Custom Parameter.

In its property editor, name it Distance, set the default value to 0.2, and set the Value Range - Minimum to 0 and the Maximum to 3. Click OK.

14. In the expression editor, replace the 0.2 with the name of the new custom parameter that represents the ball’s distance so that it looks like this:

Fc * SoccerBall.Force.distance 

Apply the expression and play the animation while dragging the sliders in combination to get the animation you want. You can also key the custom parameters to make the animation you want, you could set expressions for the ball's rotation to get a spin, or animate the scaling of the ball to get a squash and stretch effect.


This page was last modified 10:58, 4 Nov 2005.
This page has been accessed 4863 times.