unbuffered keyboard input delay

Hello,

I’m having a weird issue of input delay with Input.GetAxis().
I had not this issue before, suddently appered after writing a kind of complex script so I wrote back a simple script and the behavior is still present… I have like half of seconde of input delay when pressing a key.

My scene is basic, its just a cube with box collider and rigibody on top of a flat terrain, I’m directly setting the velocity so I doubt it has anything to do with friction or stuff like that.

Here the script:

function Update(){

    if(Input.GetAxis ("Horizontal") == 1)
        rigidbody.velocity.x = speed;
		
    else if(Input.GetAxis ("Horizontal") == -1)
        rigidbody.velocity.x = -speed;

    else
        rigidbody.velocity.x = 0;
}

Thank you.

Try GetAxisRaw as it will output -1, 0, 1. GetAxis will smooth the input, which may take up to half a second to reach the maximum.

Alternatively, you could use:

function Update(){

    if(Input.GetAxis ("Horizontal") > 0)
        rigidbody.velocity.x = speed;

    else if(Input.GetAxis ("Horizontal") < 0)
        rigidbody.velocity.x = -speed;

    else
        rigidbody.velocity.x = 0;
}

to accomplish the same thing as in @terdos 's answer but still allow for an analog input somewhere down the line (if that’s what you’re after).