GetAxis Horizontal not responding to input

Hi. I’ve run into an issue I have not been able to debug myself. This is from the Argon Assault rail shooter course. I am using Unity 2022.3.

Here is the relevant code:

void Update()
    {

        float horizontalThrow = Input.GetAxis("Horizontal");
        Debug.Log(horizontalThrow);

        float verticalThrow = Input.GetAxis("Vertical");   
        Debug.Log(verticalThrow);
    
    }

During play, vertical axis input (with WASD/arrow keys or gamepad) returns values of 1 to -1 in the console. Horizontal axis input does not respond to input and returns 0. The script is attached to PlayerShip, the new input system is not installed, the Project Settings/Player/Configuration tab is set to Input Manager (old), URP/HDRP is not set up.

I have tried: opening an entirely new project and pasting the script onto a plain cube (gives exactly the same result), going through the Input Manager to make sure that every horizontal/vertical axis was set up correctly, and… copying and pasting the course code from the GitHub. I must have missed something obvious somewhere but I’m out of ideas.

I kept going in the hope that it was just reading out wrong somehow but immediately ran into other problems related to movement that I assume are connected. I was wondering if anyone had any ideas.

I pasted the code above into a clean project and it works fine. I used Unity 2022.3.5f1 and made no changes to any settings. I cannot tell you how to fix the problem, but I suspect that this may perhaps not be a Unity issue at all but rather OS or hardware. You may want to ask around on the Unity Forums or the gamdev.tv discord

Interesting. Thanks for your response. I’ve now tried uninstalling and reinstalling the editor with no change, as well as trying the code on a more recent version of the editor, so you might be right.

What’s weird is I have continued to needle at this and went through the next section of code and it seems that input is actually being read, it’s just a) not registering on the console and b) unavailable during the timeline animation. If I place the script on the Player Rig rather than on PlayerShip (which is not how it was done during the course as far as I can tell? I might have done something wrong though) I can now move the ship horizontally and vertically. Without doing that, Unity would wait for the timeline to complete its entire animation before any input went through (even though the Y input was registering on the console!) This is all fully beyond me. I’m just glad it’s working.

Leaving this comment in case anyone else has an issue similar to it.

Hi rainlight,

What you describe sounds as if the timeline animation animates the same game object you try to move via code. If that’s the case, the animation overrides the changes applied by your code. After the animation ended, you should be able to move your ship.

  • Animate only the PlayerRig (= the parent game object), not any of its children.
  • Move the PlayerShip (= the child of PlayerRig) via code, not the parent.

See also:

Hi Nina. I had a look at my setup and the Master Timeline is set to animate the PlayerRig, and the script was on the PlayerShip as you describe – that seems to give me the input error, but putting the script on the PlayerRig seems to have fixed it. I must have done something else wrong I suppose. Unsure if this counts as a real solution given that it seems to be technically wrong, but everything is working as expected now so I guess it’s solved!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms