Stop The Xbox Joystick Moving From The Centre Position

How can i stop the Xbox joystick moving from the centre position.

i have tried something like this:

float x = Input.GetAxis("Mouse X Xbox");
   if( x < 0.1  && x > -0.1)
   {
     x = 0;
   }

I think you might be using the wrong operator. Have you tried it with || instead of &&?

I’d start with just doing a Debug.Log() of the value that GetAxis is giving you. The code you posted should do exactly what you want, so my next thought would be bad data. Things that come to mind:

  • The joystick is badly centered, so at a rest position, it is providing a value out of that range.
  • The joystick is old and has a lot of noise in it, so you need to specify a larger dead-zone.
  • There is another input which is mapping to that axis (such as the mouse)
  • The range isn’t what you expect (i.e. it’s actually 0 to 1, or -100 to +100) so the values provided aren’t causing the proper restriction.

Another thing to consider is an error elsewhere. Did you remember to use x later on in the program, or are you still reading from GetAxis directly? etc.

You are best to utilize the Input Manager and setting the Deadzone to 0.2 (this is usually pretty good for the sticks natural drift), and 0.1 for the triggers if they are giving you an issue.