- Home /
The question is answered, right answer was accepted
X-Axis inverted on 360 controller but not keyboard
I've been working on my game for a while without any interest in making it work with a controller, but by accident I discovered that the player could already use the controller, partially. I've been going through my scripts and changing the controls to the input buttons instead of accessing keys directly. Everything works with a controller now, except while holding left on the keyboard, the player rotates to the left as expected. On the controller, however, holding the analog stick left make the player rotate to the right, and vice versa. Here's my movement script, it makes for some really smooth space ship movement.
public float accelerationForce = 10f;
public float rotationForce = 3f;
void MoveShip ()
{
float rotation = Input.GetAxis("Horizontal");
float acceleration = Input.GetAxis("Vertical");
GetComponent<Rigidbody>().AddTorque(0, 0, rotation * rotationForce * Time.deltaTime);
GetComponent<Rigidbody>().AddForce(transform.up * acceleration * (accelerationForce * Time.deltaTime));
}
I don't know if it is relevant, but my game is 3D, set up as 2D. Like, all of the object in the game have 3D models, but the camera is orthographic and all the action takes place at 0 on the z axis.
EDIT: Also possibly relevant, accelerationForce and rotationForce have been set to 300 & 200, respectively, in the inspector.
Answer by Eno-Khaon · Apr 13, 2016 at 08:40 AM
In the Input Manager --Edit>Project Settings>Input-- under the default listings, you will see two labeled "Horizontal"
One of them is for keyboard input (AD and left/right arrows) and the other is intended for analog input from a joystick/gamepad.
There is also a toggle to Invert directional controls, so correcting this should prove very simple.
That was it, I never noticed the second version of each input label, so thanks for bringing them to my attention. I had to invert the second one, to un-invert it, which I find strange.
Same here but with an Xbox One controller where Y/Vertical had to be inverted!
Follow this Question
Related Questions
Rigidbody.AddTorque/AddForce Question. 1 Answer
Why isn't AddTorque working on this character? 0 Answers
AddTorque doesn't rotate? 3 Answers
What is the official (according to Sony) way to set up a PS3 controller? 0 Answers
Issue with Rotation behaviour of PID Controller when rotating to look at mouse position 0 Answers