- Home /
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.
That lag is a feature of GetAxis. You can set the rise/fall speed (in the Input $$anonymous$$anager) so it gradually ramps up to 1 however fast you want it to.
Answer by terdos · Jun 10, 2011 at 06:10 PM
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.
Sorry for late response, and thank you very much, this did the trick.
6 years later, and this answer is still the solution :)
Answer by Chris D · Jun 10, 2011 at 06:29 PM
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).
[edit]See you've edited the answer, so never $$anonymous$$d ;)
Oops, Thanks for catching that! The point I was trying to make is that you can still use the smoothed values of GetAxis but, as per @terdos 's answer, the function may not immediately return a 1 or -1 value and ins$$anonymous$$d be somewhere between 0 and +/-1.
Thank you this solution work too, althrough using GetAxisRaw allow me to write smaller code by using it directly in the equation.
Your answer
![](https://koobas.hobune.stream/wayback/20220612101314im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to prevent input lag/delay? 1 Answer
How do I fix the input delay on Unity for Mac? 0 Answers
Animation delay until certain distance 3 Answers