- Home /
Input.GetAxis - never returns to 0
Hi, in a 2 rows project i'm going crazy!!!!! USB joystick
a Simple Input.GetAxis("Horizontal") inside update method. if i write to console log, i see that value starts from 0 but when i release the stick it goes from 1 to -1 but never goes to 0.
with mouse and keyboard it's all right but mouse does not work. please help me
Answer by Bunny83 · Mar 30, 2020 at 03:24 PM
There are two things you should check:
First of all make sure in your OS / input device config that you calibrated your joystick properly. Without proper calibration it's not asured that the information that comes from the OS / input drivers is actually 0 when in the center.
Second you can increase the "dead" value in your input manager for your joystick axes to increase the dead zone. Note that the virtual axes "Horizontal" and "Vertical" are usually defind several times. You need to find the one that actually maps your joystick (not mouse or keyboard).
Answer by twrabetz · Mar 30, 2020 at 03:16 PM
Are you saying that when you leave the stick in the center, it goes close to 0, but not 0?
If you're testing your axis output and you need it to be exactly 0, instead you can test if it's close, for example instead of: if( Input.GetAxis("Horizontal") == 0 ) you can do: if( Mathf.Abs(Input.GetAxis("Horizontal")) < 0.0001 ) or some small number like that.
You can also save it in a variable and change it to 0, like:
float f = Input.GetAxis("Horizontal"); if( Mathf.Abs(f) < 0.00001 ) f = 0;
Answer by humanimsu · Mar 30, 2020 at 03:17 PM
I haven't worked with joysticks before, but you might want to just set a threshold before it activates. i.e.
if (Input.GetAxis("horizontal") > Mathf.Abs(0.15f)) {
// Your logic here
}
Answer by irombeach · Mar 30, 2020 at 03:55 PM
First of all, thanks! The problem was hardare related. I plugged XBox one controller to the pc and axis now are magically woking! thanks.
Your answer
Follow this Question
Related Questions
GetAxis for MouseX for web player. 0 Answers
How to put limits in Z? 0 Answers
Detecting cross platform input? 0 Answers
Mouse event build up? 0 Answers
Animtion looping if joystick is held 0 Answers