Smooth Jump

Blitz3D Forums/Blitz3D Beginners Area/Smooth Jump

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.

Ok, let's start there then. I see a number of errors that will need to be fixed.

first, start with your jump function.
Function jump()
If KeyHit(57) Then
	jump = True	
	For i=1 To 100
		TranslateEntity camera,0,0.01,0
	Next
	jump = False
EndIf
End Function


When you enter the function, you set the jump flag to true, then at the end you set it to false. There is no reason to do this in the code you provided, since you do not refer to this variable. You do have it in your main loop, but it will always be false because of the above code.

next, you move the camera 100 times in small steps, but there is nothing else going on (no frame updates, so this will appear as one movement when you do update the frame.

A much better way to do this is with a velocity and a gravity variable. Then all you need to do is add gravity to the value each loop through (even when jumping) When you wish to jump, you set the vertical velocity to an amount that will give you the proper jump height, and then let gravity do it's thing. (The gravity will slow the jump, and eventually return the player to the ground in a nice arc.) You will simply need to detect for a ground collision so you do not continue to fall once you hit the ground.