How do I add smooth jumping in this code???

Blitz3D Forums/Blitz3D Beginners Area/How do I add smooth jumping in this code???

NerdyBrendan(Posted 2010) [#1]
Hi,
I want to add a smooth jump to "player" in this code, but I don't know how...
any ideas???

Graphics3D 1024,768,0,1
SetBuffer BackBuffer()



AmbientLight 255,255,255

light=CreateLight()

world=CreatePlane()
PositionEntity world,0,-4,0
EntityColor world,255,0,0

camera=CreateCamera()
CameraRange camera,5,5000
;Set fog
CameraFogColor camera,255,255,255
CameraFogRange camera,1,1000
CameraFogMode camera,1

player=CreateCube()
PositionEntity player,0,0,5

;collisions
EntityType player,1
EntityRadius player,1.0
EntityType world,2
Collisions 1,2,2,2





While Not KeyDown(1)
	

	If KeyDown(17)
		MoveEntity player,0,0,0.3
	EndIf
	If KeyDown(31)
		MoveEntity player,0,0,-0.3
	EndIf
	If KeyDown(30)
		TurnEntity player,0,2,0
	EndIf
	If KeyDown(32)
		TurnEntity player,0,-2,0
	EndIf  
	

	
	
	;End stuff
FlushKeys()
UpdateWorld
RenderWorld
Flip

Wend
End



Aussie(Posted 2010) [#2]
Here you go.

I have commented the code so you can see what is going on.

Press the space bar to jump.
There is a way to set a flag\condition so when you are jumping you dont jump again.

Graphics3D 1024,768,0,1
SetBuffer BackBuffer()



AmbientLight 255,255,255

light=CreateLight()

world=CreatePlane()
PositionEntity world,0,-4,0
EntityColor world,255,0,0

camera=CreateCamera()
CameraRange camera,5,5000
;Set fog
CameraFogColor camera,255,255,255
CameraFogRange camera,1,1000
CameraFogMode camera,1

player=CreateCube()
PositionEntity player,0,0,10

;collisions
EntityType player,1
EntityRadius player,1.0
EntityType world,2
Collisions 1,2,2,2

gravity#= .01 ;Sets the gravity

yvel#=0 ;Sets the Y Velocity of the player to 0


While Not KeyDown(1)
	

	If KeyDown(17)
		MoveEntity player,0,0,0.3
	EndIf
	If KeyDown(31)
		MoveEntity player,0,0,-0.3
	EndIf
	If KeyDown(30)
		TurnEntity player,0,2,0
	EndIf
	If KeyDown(32)
		TurnEntity player,0,-2,0
	EndIf  
	
	If KeyHit (57) ;If the space bar is hit Y velocity is set to .7
		yvel = .7
	EndIf
	
If EntityCollided (player,world) Then ;If the player is touching the ground set the Y velosity to 0
	yvel = 0
	
	Else yvel = yvel - gravity ;If the player is not touching the ground Y velocity = Y velocity - Gravity amount
EndIf



TranslateEntity player,0,yvel,0,True ;Will constantly move the player whatever the Y velocity is
								     ;True wil set global X,Y,Z AXIS although it is global as default.
	
	
	;End stuff
FlushKeys()
UpdateWorld
RenderWorld
Flip

Wend
End



NerdyBrendan(Posted 2010) [#3]
Thanks heaps!!!!!


stanrol(Posted 2010) [#4]
cool ;)