Public Group

# Problem with jumping

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have promblem with making my camera jump in the x and z direction the camera jumps fine in the y direction but it runs round the map like a head-less chicken if i try a directional jump. heres the code that does the jump i would be grateful if anyone could tell me where i gone wrong.

//this start off the jump
void CCamera::Jump()
{
if(!m_IsJumping) //don't want to be able to jump while jumping
{
m_IsJumping = true;

m_Vel.y = 20.0f;
m_accel.y = 1.0f;

iPos = m_Pos; //store old posistion for landing
}
}

//this animates the camera
void CCamera::Animate(scalar_t deltaTime)
{
if ((m_yaw >= 360.0f) || (m_yaw <= -360.0f))
m_yaw = 0.0f;

//Controls Maxium and minium angle of camera
if (m_pitch > 60.0f)
m_pitch = 60.0f;
if (m_pitch < -60.0f)
m_pitch = -60.0f;

//calculate angles

//set speed of movement
float speed = m_Vel.z * deltaTime;
float strafeSpeed = m_Vel.x * deltaTime;

//limit speed of movement
if (speed > 15.0)
speed = 15.0;
if (strafeSpeed > 15.0)
strafeSpeed = 15.0;
if (speed < -15.0)
speed = -15.0;
if (strafeSpeed < -15.0)
strafeSpeed = -15.0;

//set camera acceleration
if (m_Vel.Length() > 0.0)
{
m_accel.x = -m_Vel.x * 1.5f;
m_accel.z = -m_Vel.z * 1.5f;
}

m_Vel.x += m_accel.x*deltaTime;
m_Vel.z += m_accel.z*deltaTime;

//calculate camera posistion
m_Pos.x += float(cosYaw)*speed;
m_Pos.z += float(sinYaw)*speed;

m_look.x = float(m_Pos.x + (cosYaw*cosPitch));
m_look.y = float(m_Pos.y + sinPitch);
m_look.z = float(m_Pos.z + (sinYaw*cosPitch));

gluLookAt(m_Pos.x, m_Pos.y, m_Pos.z,
m_look.x, m_look.y, m_look.z,
0.0, 1.0, 0.0);

/*****************JUMP CODE*****************************/
//czech for jump
if(m_IsJumping)
{
if(m_Vel.y > -20) //don't want to fall to fast
{
m_Vel -= m_accel;
m_Pos += m_Vel;
}
}

if(m_Pos.y <= iPos.y) //landed
{
m_Pos.y <= iPos.y;
m_Vel.y = 0.0f;
m_IsJumping = false;
}

}


any clues? Wardrobe

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633330
• Total Posts
3011388
• ### Who's Online (See full list)

There are no registered users currently online

×