# Problem with steering in an airplane flying game

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

## 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 on other sites
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?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634092
• Total Posts
3015437
×