XInput (SharpDX) not returning 0 on thumb sticks when they're idle

When querying XInput for the status of the thumb sticks, it doesn't return 0 when the sticks are not in a moved position.

Instead, it returns an arbitrary value which is a small portion of the value the stick was moved to before returning to idle state. Every other button and trigger on the controller correctly returns 0 when not engaged.

I poll the controller in the main loop with Controller.GetState, so the state of the device should always be current.

The XInput documentation asserts that a value of 0 is to be expected when the sticks are not in use.

I've worked around the problem by moving the player only if the stick is moved by 10% or more of it's possible movement limit, but I'd like more precise stick control.

Any assistance would be gratefully received.

This sounds like a fairly normal issue. Analog sticks are notoriously imprecise, and develop a drift over their lifetimes. (If you've ever had such a well-used gamepad that when you boot up some games, your character has a bit of a lean to one side or even moves slightly when the stick is "idle", that's this effect).

Games typically compensate for this by processing the raw stick value to apply what's called a "deadzone" — a cutoff value below which small drifts are considered zero. The same can be applied at the high end, to ensure the distance from the center caps out at exactly one in every direction, rather than having a bias in some direction.

Searching for "analog deadzone" will let you find different strategies for applying this, such as this previous answer.

The XInput documentation itself calls this out as something to be aware of and gives guidance for how to implement deadzones in your game code:

In order for users to have a consistent gameplay experience, your game must implement dead zone correctly. The dead zone is "movement" values reported by the controller even when the analog thumbsticks are untouched and centered. There is also a dead zone for the 2 analog triggers.

Note

Games that use XInput that do not filter dead zone at all will experience poor gameplay. Please note that some controllers are more sensitive than others, thus the dead zone may vary from unit to unit. It is recommended that you test your games with several Xbox controllers on different systems.

Applications should use "dead zones" on analog inputs (triggers, sticks) to indicate when a movement has been made sufficiently on the stick or trigger to be considered valid.