Jump

Blitz3D Forums/Blitz3D Beginners Area/Jump

Happy Llama(Posted 2009) [#1]
I am trying to find out how to have the camera jump. But i would like to have the camera touching the ground before i can press the space bar and make it jump again.


Warner(Posted 2009) [#2]
Can you show what you have so far?


Ross C(Posted 2009) [#3]
Your best bet is to either:

Do a linepick downwards and check the pick distance,

or

Check for collisions between the player and the ground, then do a normal check.

I personally prefer the linepick method.


sswift(Posted 2009) [#4]
Here's a simple way to do what you want.

Create a variable, CameraVy. That is the camera's velocity (speed) on the Y axis.

Create a second variable, Gravity. Set it to however much you want the camera to move down each frame. Let's say Gravity = 1 to start.

Create a variable JumpSpeed. Set it to some value significantly larger than gravity. Like say 10.

Create a variable Jumping.


Now, when the player hits space, if Jumping = False, set Jumping to True and set CameraVy to JumpSpeed.

Then, each frame that Jumping = True, do the following:

Move the Camera along the Y axis in the direction specified by CameraVy. Ie, TranslateEntity Camera, 0, CameraVy, 0 should do the trick.

Subtract Gravity from CameraVy.

Check to see if the camera is currently collidning with the ground. If it is, set CameraVy to 0, and set Jumping to False.


And that's it. When you hit space the camera will begin moving upwards. It will gradually slow down (because Gravity is being subtracted from CameraVy each frame), and then it will begin falling. When it touches the ground again, the physics code is disabled.