Jump function for moving 3D space

Started by
6 comments, last by cfoks 17 years, 11 months ago
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?
Advertisement
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.
Boost::Jump
Do you know a basic source code for jumping to study?
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;}
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.
enum Bool { True, False, FileNotFound };
Thank you very much for your care...
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?

This topic is closed to new replies.

Advertisement