- Home /
how do I get controller input
I'm trying to get input from an Xbox controller's left joystick using the Input.GetKeyDown command and I don't understand how to, if (Input.GetKeyDown("d")) { rb.AddForce(new Vector2(150, 0)); transform.Rotate(0, 0, 5); } if (Input.GetKeyDown("a")) { rb.AddForce(new Vector2(-150, 0)); transform.Rotate(0, 0, -5); } if (Input.GetKeyDown("space")) { rb.AddForce(new Vector2(0, 200)); }
how do I switch the Input.GetKeyDown to work with a controller
Answer by QuitsDoubloon · Dec 22, 2020 at 05:45 PM
Controler Sticks Use an Axis from -1 to 1. Unity has created the same thing for WASD as well called Input.GetAxis("AXIS_NAME"). So switch Input.GetKey to Input.GetAxis for keyboard and controller. read more here: https://docs.unity3d.com/ScriptReference/Input.GetAxis.html
it seems to be what I want but I just don't understand how it all works and how I'm supposed to make it work, do you have any stuff that goes more into it?
update: I figured out how axis work but don't understand how to map that to the controller, sometimes it player 1 move instead of player 2, sometimes it controls both, and sometimes it just breaks the game, do you have a way to fix it?
Your answer
![](https://koobas.hobune.stream/wayback/20220613022030im_/https://answers.unity.com/themes/thub/images/avi.jpg)