- Home /
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 know nothing about XBox, so I don't have idea if this can apply to your case: I saw a similar question some time ago, and the reason was a "forgotten" device connected to the XBox (both were controlling the same axes). Other possibility: could you have two "$$anonymous$$ouse X Xbox" axes declared in the Input manager, but connected to different devices?
Answer by formidable · Sep 07, 2011 at 01:12 AM
I think you might be using the wrong operator. Have you tried it with || instead of &&?
No, the operator is correct: if x lower than 0.1 AND higher than -0.1 then force it to 0; in other words, if x between -0.1 and 0.1, force it to zero.
Answer by Ipsquiggle · Sep 07, 2011 at 02:28 AM
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.
i have no errors throughout the application and also i am using the "x" variable throughout the application
I also checked the joystick value through the debug statement. the xbox controlles uses and value between 0 to 1.
So if the value is between 0 and 1, then you should be centering at 0.5? I don't have an xbox controller myself to test this with.
Other than that, I'm out of ideas, sorry.
Answer by DaSquanto · Dec 01, 2016 at 11:47 AM
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.
Your answer
Follow this Question
Related Questions
How to use a PS3 controller to control an FPS 2 Answers
Basic character movement with joystick 1 Answer
Generic USB Controller axis issue 0 Answers
How many usb joysticks can i connect to a pc? 0 Answers
Joystick DPad axis to bool 1 Answer