Input.GetAxis("Horizontal") and Input.GetAxis("Vertical")

Why does the Input.GetAxis(“Horizontal”) have to be negative to correctly move left and right while Input.GetAxis(“Vertical”) does not?

Hi Krop,

What exactly do you mean? If you pressed the “down” key mapped to Input.GetAxis(“Vertical”), you would get negative values, too.

In the video, Rick changed the Input.GetAxis(“Horizontal”) to negative because when he pressed left or right, the object was moving the opposite direction. But that wasn’t the case for Input.GetAxis(“Vertical”) because when he pressed down or up, the object moved the way it should be.

Oh, I see. Do you experience the same behaviour in your own game? If so, check the Main Camera game object. Is the scale negative or is the camera rotated?

Actually, you are right. Input.GetAxis(“Horizontal”) should return a negative value when a “left” key is being pressed, and a positive value when a “right” key is being pressed. If you have to make the value negative yourself in your code to make the player move left with a “left” key, the reason is usually a rotation or a negative scale.

I see, it makes sense now. Thank you so much!

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

Privacy & Terms