Pitch direction

I am not sure if I have done something wrong or the pitch directions are set differently then I would expect. Right now, when I use a joystick in a flight sim program, if I push forward the plane goes down. If I pull back, the plane goes up. HOWEVER, in my game for this project if I push forward the plane goes up and if I pull back the plane goes down. This is completely backwards to anything I have used before.

I think my code is the same as Rick’s code so I am checking to see if I have done something wrong or if pitch is indeed set this way for this game. And if this is the way the controller is set up how do I change the directions so that when you pull back on the joystick, the plane goes up and when you push on the joystick, the plane goes down.

Thanks and below is the code that I have written.

Hi Richard,

Before you start looking for the problem in your code, check the scale values of your camera. Make sure they are not negative.

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?

If so, what happens if you use the keys on your keyboard to move your ship? Do you get the same outcome?

See also:

The keyboard commands work as I would expect them to work. “W” makes the ship go up, “S” makes the ship go down and “A” and “D” makes the ship go left and right. It is just the gamepad (which is actually doing the same thing as the keyboard. If you pitch forward it goes UP (and intuitively in a real rocket or plane it should make the craft go down). Likewise when you pulled the stick back, it instinctively means you are going up, consequently the phrase in flying when you are too low is “Pull Up!”

Is the problem in the key binding in Unity? What if I set up the keyboard to have “W” pitch the plane down and “S” pitch the plane up?

Thank you yet again :slight_smile:

Oh, and I forgot to mention that the Camera scale is and was set to 1,1,1 on the three axes. There was only negative values for the camera in rotation and position.

If the gamepad is doing the same thing as the keyboard and if the keyboard commands work as you expect them to work, I’m wondering why you are surprised by the outcome. Maybe I’m misunderstanding your problem. What is the desired behaviour in your game? And would you like to see a difference between the keyboard input and the gamepad input?

You could take a look at the input manager to see if you could reconfigure the behaviour/interpretation of the values returned by GetAxis.

Maybe you’ll have to modify your code a bit to get the desired result.

Thanks, I will read the manual. I guess my only problem is that a joystick or game pad should react the same in a simulation as a yoke or joystick on a real airplane. As I have it set up in the game now, pitch is backwards. I am just wondering whether I have done something wrong or if indeed the control for pitch in this course code is setup so that pitch up for the ship is forward on a gamepad and W on the keyboard and pitch down is pull back on the gamepad and S on the keyboard.

If that is the way the code sets it up, then I have done the code correctly. If that is not the way it should work than I need to address my coding problem.

When W (keyboard) or “up” (gamepad) are pressed, the value returned by GetAxis “moves” towards (1). And for S and “down” respectively, it moves towards (-1). That’s on Unity’s side.

In our code, we use the returned value to move the ship up (1) or down (-1). If you multiply that value with (-1), you could, for example, flip the direction.

As for the gamepad controls, it’s more a matter of personal preference if one feels more comfortable with a video-game control where you go up on the stick if you want your player character to move up on the screen (same as ‘w’ or up-arrow on the keyboard) or if you prefer to have it flight-sim like where pulling the stick “towards you” means “raise the nose” to fly upwards.

Best option would be to have a config screen where the player can select either option (and as Nina mentioned, it’s really just a factor of -1 in some part of the calculations). Since we’re not there yet (implementing a screen where the player can do configurations), I’d keep it simple for now. If you feel like implementing the option to flip vertical directions, just expose some variable as a SerializedField.

Defining the gamepad up/down to be reversed should just be a simple configuration for the InputSystem. Or just define your keys upside-down and multiply by -1 for your vertical movement…

Okay, thanks for the information. I wasn’t sure if there was indeed a video-game control that is not the same as an airplane sim in the direction of up and down. You answered that for me. I appreciate it. Now that I know there is a difference and that my code and controls of the ship in this course is the same as the example, I will follow along with the setup of the controls as they are. I think my problem is that I way overthink the situation many times. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms