I whipped up this little demo to show basic gravity and a ball bouncing. The problem is that it's buggy as heck. Sometimes it bounces super high. Other times it bounces twice and stops. See anything wrong?
btw: if you want to run it you need the vector.bb lib from the archives
btw: if you want to run it you need the vector.bb lib from the archives
;// Gravity and Bounce Example Graphics3D 800,600,16 SetBuffer BackBuffer() Include "vector.bb" ;// Set Gravity meters per sec g# = -9.8 ;// Ball Parameters ball = CreateSphere() ScaleEntity ball,0.5,0.5,0.5 mass = 10 ;// Set Initial Forces and Vectors vFor.vector = vector() ;force vector vAcc.vector = vector() ;acceleration vector vVel.vector = vector() ;velocity vector vPos.vector = vector(0,20,0) ;position vector ;// Timing NewTime% = MilliSecs() OldTime% = NewTime ;// Camera and Lights camera = CreateCamera() PositionEntity camera,0,0,-20 light = CreateLight() ;// Main Loop While Not KeyHit(1) Cls ;// Find Delta Time NewTime = MilliSecs() delta# = Float (NewTime - OldTime) / 1000 OldTime = NewTime FPS = 1 / delta ;// Reset Forces to Zero Each Cycle Vector_Reset vFor ;// Calculate Gravity vFor\y = g * mass ;// Collision If vPos\y < 0 Then Collided = True If Collided = True speed# = Vector_Magnitude(vVel) collided = False vFor\y = -vFor\y * (Float (speed / 2)) * mass vVel\y = 0 EndIf ;// Up Arrow Key applies 100 force upwards If KeyDown(200) Then vFor\y = 100 ;// Calc New Acc, Vel, and Pos Vector_DivideScalar vAcc,vFor,mass Vector_AddTimeStep vVel,vAcc,delta Vector_AddTimeStep vPos,vVel,delta ;// Position the Ball Vector_PositionEntity ball,vPos UpdateWorld RenderWorld ;// Show What's Happening Text 5,5,"FPS=" + FPS Text 5,50,"Speed=" + Int(Vector_Magnitude(vVel)) Vector_Show(vFor,5,100,"Force") Vector_Show(vAcc,5,175,"Acc") Vector_Show(vVel,5,250,"Vel") Vector_Show(vPos,5,325,"Pos") Flip Wend End