- Home /
Why does InputManager have multiple axes with the same name?
By default there seem to be a few axes which the input manager has multiple copies of. They are even visible here: http://docs.unity3d.com/Documentation/Components/class-InputManager.html
For example there are two instances of Horizontal, Vertical, File1, ...
How do you know which one you are referring to when you use Input.GetAxis("Horizontal")
Why are they there by default are they supposed to represent a second player's controller or something?
This is a bit confusing and I was surprised to not find other users asking about this when I searched.
Answer by Eric5h5 · Jul 20, 2013 at 08:54 PM
So you can have input from more than one source without having to write any extra code. In the case of the two default Horizontal axes, for example, one is for the keyboard and the other is for joysticks. You can't distinguish between them; the point is that you don't have to.
Can you clarify how Input.GetAxis("Horizontal"), for example, references only one or the other? Or perhaps I am understand this wrong. Can you help clarify how this works?
It doesn't reference only one or the other, that's the point.
To clarify a bit more it does reference both at the same time. So pressing "D" (for moving left) will make the Horizontal axis to snap to "+1" while pressing "A" (for moving right) will return the value "-1". At the same time when any x-axis of any attached joystick is tilted to the right it would also return a value of "+1".. Of course mixing joystick input and pressing D or A at the same time might cancel each other. However that's not much different from pressing D and A at the same time.
If you don't want this behaviour feel free to remove any axis you don't want or if you want those input values seperate just rename one of the axes.
Got it. It reads them both. Now I completely got it!
Your answer
Follow this Question
Related Questions
Joystick Axis 9&10 with more than 2 gamepads 0 Answers
Quirk in Input.GetAxis 0 Answers
How do I add a value to anywhere Input.GetAxis("Horizontal") is called? 1 Answer
Input Snap option not returning 0? 0 Answers
input resets after scene change,Held Down Input not responding after scene change. 0 Answers