So i have been wanting to program some physics in my games for some time now. But untill now I have only thought of doing so. But the other day i tried and tried to make this ball start at the top of the screen.
and as long as it is above the bottom of the screen then it shall fall.
once it hits the bottom its speed is reversed and a variable called decel is subtracted from the total speed so it looses a bit of speed untill finally it has none. and according to my thought process. the ball should bounce... bounce...bounce... and then stop once the speed reaches zero. because when speed is zero. usually things stop right?
well i cant seem to get this ball to find rest. it likes to bounce... bounce .... bounce.. and once it looses a certain amount of speed. it continues to bounce within a small range at the bottom of the screen.
I am using Blitz3D but i am only using 2D functions and therefore only 2 dimensions. I just want to get this to work....
here is my code:
;Create player type
Global ball.ball = New ball
While Not KeyHit(1)
;If ball is above bottom then fall
If ball\y =< GraphicsHeight()-50 Then ball\speed = ball\speed + ball\accel
;If the ball has touched the ground then reverse the speed and decelerate
;Make sure the ball doesn't exceed terminal velocity(topspeed)
If ball\speed = ball\topspeed Then ball\speed = ball\topspeed
;Make the ball move at speed given
ball\y = ball\y + ball\speed
;Draw the ball and draw the ball speed at the top left corner of the screen
Text 0,0, "speed:" + Str(ball\speed)