Sunday, 27 September 2009

gravity with speed

onClipEvent (load) {
// gravity is what I called g in the tutorial. The
// higher g the harder the ball will fall.
// gravity = 0 can be set, as an experiment, but
// it will in fact create a "zero gravity" effect
// gravity < 0 will create an inverted gravity effect
gravity = 2 ;

// We set the speed of the ball when it is released.
speedx = 0 ;
speedy = 0 ;
}

onClipEvent (enterFrame) {

// We calculate the increase of speed
// speedx doesn't change
speedy = speedy + gravity ;

// We move the ball.
// speed/5 just makes the motion slower
this._x += speedx/5 ;
this._y += speedy/5 ;
}

//have fun

No comments: