- Home /
Input.GetAxis(Horizontal) problem
Wen i use Input.GetAxis("Horizontal") its pressing alone all by itself, i even tried unpluging the keyboard and nothing, this is a little code i used to figue it was failing:
function Update () {
if(Input.GetAxis("Horizontal"))
{
print("Input: " + Input.GetAxis("Horizontal"));
}
}
And what i get in the console whitout pressing any button is:
Input: -1
wish means its pressing to the left but i dont press any button.
the only diferent thing i did was update to 3.5.5f3
started the game and my character was waliking to the left o.O
i changed to previus version and the same thing keeps happenig, any ideas on what could be happening?
Answer by mikedolan03 · Dec 02, 2014 at 12:39 AM
The best way to solve this from the programmer end is to write your input scripts to deal with it. Currently, your game (by default) accepts Hortizontal and Vertical Axis info from the keyboard or a joystick. They are labeled the same in the Input Manager... That way you can write code like:
float translation = Input.GetAxis("Vertical") * speed;
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
And it wont matter if the player is using a keyboard or a joystick. Unfortunately when a player has something going on with their joystick stuff (virtual joysticks seem to cause issues), the Axis gets all wonky... Players report spinning around that won't stop.
BUT... If you change the name of your second set of Horizontal and Vertical Axes in the Input Manager (the ones that correspond to the joysticks) to something like HorizontalJoy and VerticalJoy then they won't interfere for your keyboard-only using player. You could then add a toggle on your Controls or Pause menu to enable Joystick controls.
then you might write code like this:
if( !joystick )
{
//if joysticks aren't enabled - just track keyboard axis
float translation = Input.GetAxis("Vertical") * speed;
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
} else {
float translation = Input.GetAxis("VerticalJoy") * speed;
float rotation = Input.GetAxis("HorizontalJoy") * rotationSpeed;
}
Below is a screenshot of the input manager - notice the second set of Horizontal and Vertical Axis are called HorizontalJ and VerticalJ. Do something like that and write code to allow for joy support if you want to give your user the option and the bug should be fixed on your end and the users. This also means joys won't really be tracked unless you write code to watch the specific axis as stated above. This solution worked for my testers.
Answer by aldonaletto · Aug 17, 2012 at 10:49 PM
It seems that the Horizontal axis Input settings have been screwed up - either by the Unity update or unintentionally by yourself. There are two Horizontal axes, one for button/key and the other for joystick input. Check if both Horizontal axes are set as below (default setting):
just ran into the same issue, except $$anonymous$$e was pushing right. turned out that the joystick part of Horizontal was reading 1.0 constantly. not really sure why, but by deleting the joystick copy (the 2nd horizontal entry,) it fixed my issue. obviously i need to re-enable joysticks at some point, but for my early testing stuff its fine :)
Answer by solidearthvr · Aug 10, 2017 at 11:11 PM
Similar to @jinhyuki my problem was caused by an extra non-existent HID, in my case it was a "HID-compliant game controller" that was the culprit.
Answer by jinhyuki · Feb 27, 2017 at 08:50 AM
Had a same problem.
My problem was fixed when I uninstalled virtual joystick I installed before, and disabled the virtual joystick driver.
Answer by HisakoDarkFire · Aug 28, 2020 at 09:29 PM
My fix was to set Camera to MainCamera in the Tag section, NOT the name (for new people).
Your answer
Follow this Question
Related Questions
How to have vertical and horizontal axis work at the same time 1 Answer
Horizontal as a NGUI button 0 Answers
Input.GetAxisRaw returns -1 when it should return 0 1 Answer
Why does holding down any button cause ~20-30 FPS loss? 1 Answer
How to keep position on input.get axis even when it is pressed twice? 1 Answer