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. <i>Edit: Also, for reference, your "cutout" doesn't actually mention where "x" and "z" are used. Are they a part of your "move" variable?</i>

3 Answers

3

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!

In my case i’m receiving wrong values with both 2020 & 2021 without any device connected, BT is down, no connection to any device. Dunno how to fix it.

I have the similar situation as you. Although I did not connect any Joystick, I saw a VJoy Virtual Joystick in my device manager. I solved the problem by disabling it. Maybe you can check if you have a similar virtual Joystick installed.