Jump to content
  • Advertisement
Sign in to follow this  
AntonSoder

Problem with steering in an airplane flying game

This topic is 3774 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

So, I am working on a game where you steer an airplane. I have a slight problem with the steering. It works if you only want to steer left and right and accelerate or if you only want to steer up and down and accelerate. The rotatation works perfectly. It´s the acceleration that is the problem. But it dosnt work together. The code: if(keystate[DIK_LEFT] & 0x80) airplane_x_angle+=0.2f; if(keystate[DIK_RIGHT] & 0x80) airplane_x_angle-=0.2f; if(keystate[DIK_UP] & 0x80){ airplane_y_angle-=0.03f; } if(keystate[DIK_DOWN] & 0x80){ airplane_y_angle+=0.03f; } if(keystate[DIK_SPACE] & 0x80){ airplane_x-=0.5f*sin(airplane_x_angle);airplane_z+=0.5f*(cos(airplane_x_angle)); airplane_y+=0.5f*sin(airplane_y_angle);airplane_z+=0.5f*(cos(airplane_y_angle)); } As I said the steering works perfectly besides the problem with the variable airplane_z. I have to combine the 2 lines airplane_z+=0.5f*(cos(airplane_x_angle)); and airplane_z+=0.5f*(cos(airplane_y_angle)); . But I dont know how. If I remove for example airplane_z+=0.5f*(cos(airplane_x_angle)); the vertical steering works perfectly. If I remove the other line the horisontal steering works perfectly. If I do both airplane_z reacts wrong.

Share this post


Link to post
Share on other sites
Advertisement
Actually, your question is probably better posted to another of the forums here on gamedev having to do with math/physics or game design as it isn't really DirectX related.

However, when you press up or down, your code advances the airplane along the z-axis in spite of it's "direction" in the x-z plane.

If you want to keep your model simple, why not just eliminate

airplane_z+=0.5f*(cos(airplane_y_angle));

and let the up-down keys control vertical movement and the left-right keys control movement in the horizontal direction?

Share this post


Link to post
Share on other sites
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!