Brian Chia
       
 
categories
actionscript
actionscript 1.0
actionscript 2.0
misc
 
processing
 
links
brian chia
kelvin zhao
ronald leong
 
 
Rebounce v01
 
A very simple bouncing ball. Add a friction variable to control the bounce. The friction force is there to make the y velocity gradually loses it momentum and eventuall the bounce will come to an end.

Friction can be adjust through the slidebar.


import Vector;

var velocity:Vector=new Vector(0,0);
var gravity:Vector=new Vector(0,.3);
var friction:Number=.7;

function bounce():Void{

// add gravity to velocity to create acceleration
velocity.plus(gravity);
ball._x+=velocity.vx;
ball._y+=velocity.vy;

if(ball._y-Stage.height>-ball._width/2){

ball._y=Stage.height-ball._width/2;

// reverse the y velocity, and lose momentum
velocity.reset(velocity.vx,-velocity.vy*friction);

}

}

this.onEnterFrame=function():Void{

bounce();

}



suggestion

 
 
 
         
  © copyright 2007 THINKLUNATIC.    
Brian Chia Jonathan Ng