- Home /
Input.GetAxis not returning 0 when keyboard is idle
I recently reimported an FPS shooter I was working on and noticed that my character was automatically moving without any keyboard inputs.
So I did some debugging and realized that Input.GetAxis("Horizontal)
was returning -1 and Input.GetAxis("Vertical")
was returning 1 even when nothing was being inputted. However when the application isn't in focus, both axes return 0. I have switched keyboards and I'm still facing the same issue.
Here is a cutout of my movement code:
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Debug.Log(x);
Debug.Log(z);
//Move character controller
controller.Move(move * speed * Time.deltaTime);
//Apply gravity
velocity.y += gravity * 2.5f * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
Please help!
Are there any other input devices connected to your computer that are being recognized as a sort of "game controller"? It could be unexpected/erroneous input being provided in that manner.
Edit: Also, for reference, your "cutout" doesn't actually mention where "x" and "z" are used. Are they a part of your "move" variable?
Answer by endasil_unity · Dec 29, 2021 at 09:54 PM
Do you have any type of joystick connected to your PC? By default, this is not only keyboard but also mouse and joystick input.
Wow, I just realised that I had an FPV controller constantly connected to my pc. I took it out and now it works, thankyou so much!