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

4 Answers

4

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;

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
}

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).

First of all, thanks!
The problem was hardare related.
I plugged XBox one controller to the pc and axis now are magically woking!
thanks.