# Jump function for moving 3D space

## Recommended Posts

cfoks    122
I m writing a FPS game but I could not solve the jump problem.When I press the space key I must jump.Does anyone knows a jump function in c++ or any idea?

##### Share on other sites
C++ standard libraries do not contain any first person jump functions.
You will need to write your own.

It should be a simple matter of pressing the jump key setting the player's velocity to point upwards, your physics system should then handle the resulting upwards motion as well as gravity pulling him back down automatically.

##### Share on other sites
OrangyTang    1298

##### Share on other sites
cfoks    122
Do you know a basic source code for jumping to study?

##### Share on other sites
PsuedoCode for Y (vertical) motion equations only
You will need to modify or use Vectors to include X (horizontal) motions....
lasttime=gettime();while(gameloop){  nowtime=gettime()  dtime=nowtime-lasttime;  ///Do controls and stuff Here///  if(NOT touching ground) accel= -9;//gravity points down  if(touching ground) accel=0; velocity=0; //dont fall through the floor  if(Jump) velocity=20;  velocity += accel*dtime*dtime;  position += velocity*dtime;  ///Position is what you want for your player  ///Draw stuff Here///  lasttime=nowtime;}

##### Share on other sites
hplus0603    11356
A typical movement simulator has a position and a velocity (both are Vector3).

When you want to jump, you want the velocity to suddenly turn upwards.

If you're a Y up world, you could "jump" by just setting velocity.y to some value -- say 3 (if your velocities are in m/s).

update() {  if (Jumping && haveGroundContact()) {    velocity.Y = JumpSpeed;  }  position = position + TimeStep * velocity;}

Remember to test for having ground contact -- you can't jump when your feet are not on the ground.

##### Share on other sites
cfoks    122
Thank you very much for your care...

##### Share on other sites
cfoks    122
I did a function for physics jobs but I cannot see anything because Player goes up and down and finishes the everything quickly and I cannot see anything.Do I need to slow motion When I jumped or any trick?