Sign in to follow this  
cfoks

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this