Math Functions

This movie uses the sin function to make a ball bounce.

Get Adobe Flash player

Experiment: can you make the ball go from side to side instead of up and down?
Can you make it move across the stage as it bounces?

//variables
var angle:Number=0;
var distance:Number=50;
var origY:Number=ball.y;
var rate:Number=0.5;

//initialize
this.addEventListener(Event.ENTER_FRAME,frames);

//functions
function frames(e:Event):void {
	ball.y=origY+Math.sin(angle)*distance;
	angle=angle+rate;
}//frames
Download the FLA file

NEXT: Eyes follow the cursor