- Home /
Read analog stick input without using the Input Manager
I'm making a quick prototype and there is no real reason for having a specific limit of players in the game (at this state) so I want to be able to read every single controller connected to the computer without having to make multiple axis in the Input Manager.
Answer by YesNoKonrad · Oct 18, 2016 at 12:51 AM
Yes indeed.
To ask for an arbitrary keycode you use the enumeration KeyCode.
The KeyCodes for the joysticks follow all the following formula:
KeyCode.Joystick*XButtonY where you replace X with the joystick number (order is determined by the order they are identified (i.e plugged in) by the computer) and Y with a number. numbers reach from 1 to 19.
hint: The * Behind Joystick is a bug.
for example Input.GetAxis(KeyCode.Joystick2Button1) should return either the vertical or horizontal axis of the left stick when im not mistaken.
Warning: I don't know if GetAxis() actually works with KeyCodes.
If yes, this is the way.
If no, there is only GetKey(Down/Up) left and that function only returns bool which means you cannot make decent use of the sticks without actually configuring them in the InputManager.
No, GetAxis only reads the axis deter$$anonymous$$ed in the Input $$anonymous$$anager (as I'm aware). So my only known option is to use Get$$anonymous$$ey but I already knew about that. I was hoping for a solution to get analog input without using the Input $$anonymous$$anager. Thanks anyways.
Shame. Well, that is why they work on a new Input class. Can't be done soon enough if you ask me!
Oooh, sounds exciting. I shamefully start on new projects all the time, loosing interest in my current projects. Which means that I'm always starting from scratch and wasting allot of needless time on setting up the Input$$anonymous$$anager.
GetAxis will accept a string ("axis 1", etc). What we do to deter$$anonymous$$e all available axes is generate a string (string.format("axis {0}", i)) for i = 1 to 20. Do this inside a try-catch, when the catch happens the previous i is your final available axis on the controller. I believe this is for all the connected controllers, so I'm not sure if there is a way to separate it, but is there is the string is likely "joystick 1 axis 1". This also works for the Input.Get$$anonymous$$eyDown("joystick 1 button 1"). We use the same try-catch method to deter$$anonymous$$e the joystick number connected.
They all return an error. Joystick1Axis1 and etc doesn't exist.
It's just "axis 1" and spaces and capitalization is important "joystick 1 button 1"
Your answer
Follow this Question
Related Questions
The value of Input.GetAxis("Horizontal") gets stuck when Xbox controller is disconnected... 0 Answers
360 Trigger Pressing both Triggers at the same time 1 Answer
Gamecube Controller joystick axis does not work? 0 Answers
How do configure controller trigger input in old input system? 0 Answers
Problems with joystick / controller axes being 1/-1 "way too often" 1 Answer