Jump Routine

Blitz3D Forums/Blitz3D Programming/Jump Routine

Remixed your code:
Graphics3D 640, 480, 0, 2

cam = CreateCamera()

cube = CreateCube()
MoveEntity cube, 0, 1, 20
ScaleEntity cube, 1,1.9,1
cube2 = CreateCube()
MoveEntity cube2, 3, 0, 20
cube_velocity_y# = 0

Const gravity# = 9.81      ; acceleration = meters(units) per second per second
Const jump_velocity# = 2.0 ; velocity = meters(units) per second

previous_time = MilliSecs()
Repeat
	this_time = MilliSecs()
	elapsed_time# = (previous_time - this_time) / 1000.0
	previous_time = this_time
	

	cube_velocity_y = cube_velocity_y + gravity * elapsed_time
	If KeyHit(57) Then cube_velocity_y = jump_velocity
	
	MoveEntity cube, 0, cube_velocity_y, 0
	
	If EntityY(cube) < 1 Then
		PositionEntity cube, 0, 1, 20
		cube_velocity_y = 0
	EndIf

	RenderWorld
	Text 0, 0, cube_velocity_y
	Flip
Until KeyHit(1)
End