How does Input.GetAxis work with a keyboard?

I have a simple character controller. This is a snippet from my code:

Rigidbody2D rb ; // in Start this gets gameObject.GetComponent<Rigidbody2D>()
float maxSpeed = 5f ;
...
void Update() {
...
float move = Input.GetAxis("Horizontal") ;
print(move) ;
if(move != 0)
    rb.velocity = new Vector2(move * maxSpeed, rb.velocity.y) ;
}

I can see that when I don’t press neither the Left Arrow Key (the negative axis key) nor the Right Arrow Key (the possitive axis key), Input.GetAxis returns 0, when I press the Left Arrow key, it starts returning a value that is between (-1, 0) and after about 1s of pressing it returns -1, same with the Right Arrow key but between (0, +1). I found on a forum that with a keyboard Input.GetAxis always returns -1, 0 and 1 but I get values between. Is this normal? How are this values calculated? Are they related to how long did the user press the key or how hard did he press it?

Target

As many people, I am disapointed by Unity’s Input Manager and I’m writting my own Custom Input Manger. I need to know how can I calculate theese intermediate values in my public static float GetAxis(string axisName)

Update (Clarification)

I’m writing my custom Input Manager because I need to be able to change axes at runtime.

If you need straight up full values, use GetAxisRaw. GetAxis by itself lerps the values based on the settings in the input manager, while GetAxisRaw returns the raw version of input, without any lerping. In essence, it simulates the input of a virtual joystick, where it is impossible to pull the joystick fast enough for it to instantly read -1 or 1. Usually joysticks are sensitive enough to sense that they’ve actually been moved to somewhere in between the center and the full axis, so that’s what GetAxis tries to simulate. I’m unsure whether or not the speed of scaling can be adjusted by a variable, however it would make sense for Gravity to determine it, if anything in the Input settings.

Also, if I were you, I’d just use Unity’s input manager, it’s pretty good as is and is at least guaranteed to have equal or less bugs than a custom one. Besides, it works pretty well and has plenty of functionality. Some which you, like GetAxisRaw, didn’t even notice.

As for how to determine the scaling speed of GetAxis, you’d likely just lerp the value, as said previously. Define some speed, and Vector2.Lerp the value.

The behavior you’re seeing is normal. GetAxis is a virtual joystick on top of GetAxisRaw, which executes a smoothing algorithm using a hidden velocity vector and public acceleration constants to reconcile its current output with its target output (GetAxisRaw).

Unity exposes constants which dictate the smoothing algorithm through the InputManager, which can be accessed via Edit->Project Settings->Input. Of particular importance are Gravity and Sensitivity, which impact how fast the joystick responds to non-input (0) and input (-1 and 1), respectively. A joystick mirroring the values of GetAxisRaw would have both a large Gravity and Sensitivity.

interesting, I need the gamepad to lerp from 0 to 1 etc but only the keyboard does. even if I use getaxis

seems coding a lerp for the button reaction is the way to go for me then