Tag Archives: C#

Input.GetAxis vs Input.GetAxisRaw

I recently started getting into some Unity programming with C# and was working on a character controller script to make a simple box move on a 2D plane. I was using the Input.GetAxis method to read the input from the keyboard. After a little bit of playing around, I wasn’t satisfied at all with the way the character was moving, it seemed like there was a little bit of delay when the key was pressed and also when I let go of a direction key, the character still moved a little bit as if it had some momentum. None of the physics settings seemed to fix this issue. After a bit of digging around, I found out that it was not the physics that was causing the sluggishness and over shooting, it was the input method. The Input.GetAxis method contains an inbuilt smoothing filter which automatically smooths out the key press. This means that the function won’t give an immediate full response to the key press, the return value will gradually increase from 0 to 1 as the key is pressed and decrease from 1 to 0 as the key is let go. I personally find this smoothing quite annoying and it feels sluggish for the kind of movement I want. The alternative is to use the Input.GetAxisRaw which gives a 1 when the key is pressed and a 0 when it is not. Simple and straight up.