Half a second delay before key release is detected

Hi all,

I posted this in the scripting section but I think it actually should be in here.

I noticed something relatively minor but still it is bugging me and may be a problem for me later on:

var cube : GameObject;

function Update () {
	
	if(Input.GetAxis("Vertical"))
		cube.transform.position.x -= 0.01;
	else
		cube.transform.position.x += 0.01;
}

I applied that script to the main camera and attached a regular old cube to the gameobject. What I found was when I hit the W (or S) key the cube would immediately move in the opposite direction, however when I let go of the key there would be this 0.3 second delay before the cube would change direction again.

I changed the cube transform to a Debug.Log call and I also saw the exact same thing.

What might be causing this? Is this just something to do with my computer or is this normal?

Thanks

edit: I changed the condition to Input.GetMouseButton(0) and found that mouse click and releases are detected instantly

This is the expected result. By default, “Vertical” has Sensitivity value which means the value smoothly transitions.

This is nice for things like character control where you don’t want your inputs to instantly jump between zero and one, even when using digital inputs. When you don’t want that behavior, you can either customise the values (Project Settings > Input) or use GetAxisRaw.

1 Like

ah, that makes perfect sense

thanks very much!

Uh this is interesting… I wonder why it’s implemented this way: when I release a button I expect to detect it was released immediately, not after an arbitrary lapse… if I want to add a time lapse, then I’ll add it.

I think It’s just one of those things the unity team thought would be a commonly used thing in a lot of games, and I can see it being used in a lot of games. In any case like Sycle said you can use GetAxisRaw instead =)

There is no arbitrary lapse. If you want off/on, that’s what GetButton is for. GetAxis has settings for smooth transitions as Sycle already noted, which you control in the input manager.

–Eric