Gravitation
Force = mass * g
g is a constant equal to 10 meters per second per second (m/s2)
acceleration = g
speed = g * t + starting_speed
t is the time elapsed since the beginning of the free fall
FLASH
onClipEvent (load) {
gravity = 2 ;
// This sets the _y position of the floor
floor = 500 ;
// Bounce is a number < 1 but close to 1
// The closer to 1, the higher the ball will bounce
bounce = 0.92 ;
// We set the speed of the ball when it is released.
speedx = 0 ;
speedy = 0 ;
}
onClipEvent (enterFrame) {
speedy = speedy + gravity ;
this._x += speedx/5 ;
this._y += speedy/5 ;
// If we are beyond the floor, invert the speed
if (this._y > floor) {
this._y = floor ;
speedy *= -bounce ;
}
}
g is a constant equal to 10 meters per second per second (m/s2)
acceleration = g
speed = g * t + starting_speed
t is the time elapsed since the beginning of the free fall
FLASH
onClipEvent (load) {
gravity = 2 ;
// This sets the _y position of the floor
floor = 500 ;
// Bounce is a number < 1 but close to 1
// The closer to 1, the higher the ball will bounce
bounce = 0.92 ;
// We set the speed of the ball when it is released.
speedx = 0 ;
speedy = 0 ;
}
onClipEvent (enterFrame) {
speedy = speedy + gravity ;
this._x += speedx/5 ;
this._y += speedy/5 ;
// If we are beyond the floor, invert the speed
if (this._y > floor) {
this._y = floor ;
speedy *= -bounce ;
}
}
<< Home