collisions and gravity

Blitz3D Forums/Blitz3D Beginners Area/collisions and gravity

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Example code of simple gravity-based collisions.

;; Set up collisions so that the player can walk up slopes while not sliding down them
Collisions PlayerID,WorldID,2,3

;; Main loop
Repeat

     ;; Gravity; VY = VelocityY
     VY# = VY# - .08
     
     ;; Jump
     If KeyHit(57) Then VY# = 2.5
     
     ;; Check for ground and or ceiling collision
     For i = 1 To CountCollisions(Player)
          ;; React accordingly
          If CollisionNY(Player,i) >= .1 Then
               VY# = 0
          ElseIf Abs(CollisionNY(Player,i)) >= .5 Then
               VY# = -Abs(VY#) * .64
          EndIf
     Next

     ;; Move the player
     TranslateEntity Player,0,VY#,0

     ;; Update world
     UpdateWorld

Until KeyHit(1)