Jumping

Blitz3D Forums/Blitz3D Beginners Area/Jumping

here is a simple 2d example, You didn't say 2d or 3d, but the same code would work for both.

This would also need a timer so you would not be able to continuously jump.

Graphics 640,480,0,2
SetBuffer BackBuffer()

gravity# = 1 ; set strength of gravity

;set initial position and velocities
playerXpos# = 320
playerYpos# = 240
playerXVel# = 0
PlayerYVel# = 0

While Not KeyHit (1)
	;get player Input
	playerXvel =  playerXvel -(KeyDown(203)-KeyDown(205)) ; add user movement to the X velocity
	playerYvel = playerYvel + gravity ; add gravity to the Y velocity
	If KeyHit(57) playerYvel = -20 ; if the space bar is hit, then jump

	;add velocities to the current positions
	playerXpos = playerXpos + PlayerXvel
	playerYpos = playerYpos +PlayerYvel

	; bounds checking
	If playerYpos > 400 playerYpos = 400 	;ground plane
	If playerxpos < 0 playerXpos = 0			;left edge
	If playerxpos > 630 playerXpos = 630	;right edge

	;draw the screen
	Rect playerXpos,playerYpos,10,10  ; draw the player
	Line 0,410,640,410 ; draw the ground
	Text 0,0," use left/right arrows to move, space to jump"

	playerXvel = playerXvel * .9 ; create drag for the X movement
	
	Flip
	Cls 
Wend