Jump to content
  • Advertisement
Sign in to follow this  
andrew_wardobe

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.

If you intended to correct an error in the post then please contact us.

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
     float cosYaw = (scalar_t)cos(DEG2RAD(m_yaw));
     float sinYaw = (scalar_t)sin(DEG2RAD(m_yaw));
     float sinPitch = (scalar_t)sin(DEG2RAD(m_pitch));
	 float cosPitch = (scalar_t)cos(DEG2RAD(m_pitch));


	 //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(cos(DEG2RAD(m_yaw + 90.0)))*strafeSpeed;
     m_Pos.z += float(sin(DEG2RAD(m_yaw + 90.0)))*strafeSpeed;
     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

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!