View Full Version : Jumping in 3D
Does anybody here have a game in 3D that allows the player to jump? I'm working on making a small first person 3D game engine and can't get my jumping function to look decent. If anyone could give some pointers or code on getting some realistic jumping movement in a first person 3D environment, I would greatly appreciate it.
Just make the Y velocity +2 and let gravity take car of the rest.
I'm not sure I fully understand "just make the Y velocity +2". Could you explain that a little bit.
Also, here's the code of what I'm currently using:
void CCamera::JumpCamera(float s)
{
if (!mDucking)
{
if ((m_vPosition.y+(35*s)-mDescentRate) > lastY && mJumping)
{
m_vPosition.y += 35 * s;
m_vView.y += 35 * s;
}
lastY = m_vPosition.y;
}
}
The '35' in there is the force of the jump. I just haven't put it into a variable yet. mDescentRate is basically gravity. m_vPosition.y is the y coordinate of the camera. s is the Frame Interval for frame independent motion. lastY keeps track of the last Y position. Then when gravity can overpower the upward force (the if statement) it stops adding to the Y and then it's all up to gravity to pull you back down. This works decently but I thought there may be a better method to do this.
NCarter
2004.09.07, 04:34 AM
Unless you're trying to do a variable strength jump (so that it goes further if you hold the jump button or something), you typically only need to do this:
Give the player a velocity vector, and each frame, add the velocity vector to the player's location vector. If you don't want velocity in the X and Z axes, you can do Y velocity separately and just add that value to the location's Y axis.
If the player presses the jump button while they're standing on something, apply a large upwards force to the velocity. You don't need to keep applying it over time unless you're doing variable jumps; just apply one big push and you're done.
When the player is in the air, add the force of gravity the their velocity to move them down.
That's it!
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.