Functions are shortcuts for mathematical procedures that could also be written with longer equations. A term like
5 * 5 * 5 * 5 * 5 * 5
can, for example, also be written shorter with an exponential function with the arguments 5 and 6:
pow( 5, 6 )
We will now create an expression with functions:
1. Create a Sphere with a radius of 0.5 and name it "Ball" and make it animatable.
2. Add the Position channel to the Xpressionist channel list.
3. Go to the Xpressionist editor tab and type this statement:
Ball.Position.Y = sin( time * 180 );
To be able to only calculate the Y value of the balls position we need to tell Xpressionist only to use the Y component of the Position vector channel of the object. This is done by adding a .Y to the Ball.Position.
The sine function that we have used here returns a value between -1 and 1 based on the value of the argument time * 180. The sine function is a trigonometric function and calculates with degrees. 0 will return 0, 90 will return 1, 180 will return 0 and 270 will return -1. Since we multiply the value of time with 180, the Ball will go up to Y = 1 and down to Y = 0 once in a second. In the following second the Ball will go down from 0 to -1 and up to 0 again. The Ball needs two seconds to complete one period of a sine wave. The result is a Ball that goes periodically up and down.
What if we want the Ball to jump and not to swing? We will need another function to accomplish that. Alter the statement to this:
Ball.Position.Y = abs( sin( time * 180 ) );
We have now encapsulated the term sin( time * 180 ) as an argument for an absolute function. This function will return the absolute value of the argument; that means that every value that is negative will be positive afterword. The animation in the first second stays the same as in the previous example since all values are positive when time is between 0 and 1. In the following second all previously negative values become positive resulting in the second part of the sine wave to be inverted. The Ball jumps now up and down periodically.
We will now use a custom variable to control the height of the bounce. To do this, add an effector to 2, 0, 0, make it animatable and name it "Controller". Add the Controller's Y position channel to the channel list. Modify the previous statement to this:
Ball.Position.Y = abs( sin( time * 180 ) ) * Controller.Position.Y;
Since the value of abs( sin( time * 180 ) ) will now be multiplied with the Y position value of the effector we can change the height of the bounce when we change the Y position of the Controller. To check this out set the Controllers Y position to different values and watch the result. The higher the controller object is, the higher the ball jumps.
You can also animate the Controller object's Y position and the height of the bounce will be adjusted dynamically.
We can also control the speed of the bounce with our controller object. To do so, add the Controllers Y rotation channel to the channel list and modify the statement to this:
Ball.Position.Y = abs( sin( time * Controller.Yaw_Y) ) * Controller.Position.Y;
We have now exchanged the constant 180 with the custom variable Controller.Yaw_Y. When the Y rotation is 0 the ball will not bounce at all. The higher the value is the faster the ball will bounce. To check this out just try different values for the Y rotation and watch the result. When we animate the Y rotation of the Controller we will see that the speed of the bouncing will increase or decrease when the Y rotation gets larger or smaller. When we add the Y position value and the Y rotation value to the function curve editor, we get two envelope curves for the precise adjustment for the behavior of the bouncing.
With these two Controls we can simulate the fade out of the ball's bouncing.
Summary
In this section, you learned how to
- use functions
- use functions within other functions as arguments
- use custom variables as envelopes
|