Jump Routine

Blitz3D Forums/Blitz3D Programming/Jump Routine

xmlspy(Posted 2006) [#1]
Anyone have a really good "jump" routine?


xmlspy(Posted 2006) [#2]
Here's a very simple way of doing a "jump" I'm not that good at physics... hehe.
Graphics3D 640, 480, 0, 2

cam = CreateCamera()
cube = CreateCube()
MoveEntity cube, 0, 0, 10

gravity# = .2
jumpforce# = gravity# *2.5

Repeat
	
	If KeyHit(57) Then jump = True
	If jump = True Then
		i = i + 1
		If i = 30 Then jump=False : i = 0
	EndIf
	
	If jump = True Then
		MoveEntity cube, 0, jumpforce#-gravity#, 0
	Else
		MoveEntity cube, 0, -gravity, 0
	EndIf
	
	
	If EntityY(cube) <0 Then PositionEntity cube, 0, 0, 10

	RenderWorld
	Text 0, 0, i
	Text 0, 20, jump
	Flip
Until KeyHit(1)
End



xmlspy(Posted 2006) [#3]
Using time, instead of a frame counter would be better....

How long in seconds can a human jump?


xmlspy(Posted 2006) [#4]
I timed myself... lol
first try: .45 secs
second: .61 secs


xmlspy(Posted 2006) [#5]
Here's one with time... I tried to make it a little more realistic by adding real gravity force. I do not know the force of a jump going up, but I know that is at least more than gravity's force. This does not include mass... By my previous timing I could assume that it takes about 200 milliseconds until I get pulled completely down.... I need to take some physics classes...

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

gravity# = 9.81
jumpforce# = gravity#+.2
jumptime = 200

Repeat

	If KeyHit(57) Then jump = True : im = MilliSecs()
	If jump = True Then
		tj = MilliSecs() - im
		If tj => jumptime Then jump = False
	EndIf
	
	If jump = True Then
		MoveEntity cube, 0, jumpforce#-gravity#, 0
	Else
		MoveEntity cube, 0, -gravity, 0
	EndIf
	
	
	If EntityY(cube) <1 Then PositionEntity cube, 0, 1, 20

	RenderWorld
	Text 0, 0, tj
	Text 0, 20, jump
	Text 0, 40, jumpforce#
	Flip
Until KeyHit(1)
End



Naughty Alien(Posted 2006) [#6]
..this is something I deal with and working fine..smooth jump up and going down smoth too, just put in main loop..pivott is pivot of your entity, camera, whatever..

;Jump Parameters,somewhere at begin of proggy
Global Jump_Height#=0.1
Global Drop_Speed#=0.05


;put this somewhere as Update_Jump() function and call it from main loop
If KeyHit(57) And jumping = 0 Then yvelocity# = 15 jumping = 1
CountCollisions (pivott)
If EntityCollided(pivott,2)
If CollisionNY#(pivott,1)<>0
If yvelocity#<0 Then jumping=0
yvelocity#=yvelocity#*Jump_Height#
EndIf
EndIf
yvelocity#=yvelocity#-Drop_Speed#
MoveEntity pivott,speedx,yvelocity#,speedz#
;========================================================


octothorpe(Posted 2006) [#7]
Remixed your code:



xmlspy(Posted 2006) [#8]
Now that's what I'm talking about!