
Value = CoerceValue(value, -directionalSaturation, -directionalDeadZone) Value = CoerceValue(value, directionalDeadZone, directionalSaturation) Value = -((Math.Abs(value) - directionalDeadZone) * multiplier) Value = (value - directionalDeadZone) * multiplier / Gets the joystick's direction (from 0 to 1).ĭouble angle = Math.Atan2(x, y) / (Math.PI * 2d) Value = CalculateSensitivity(value, Sensitivity) Value = CalculateDeadZoneAndSaturation(value, DeadZone, Saturation) Return (value maxValue) ? maxValue : value) Private static double CoerceValue(double value, double minValue, double maxValue) Virtual axis positions, with all modifiers applied (like deadzone, sensitivity, etc.) Each of this properties should include its axis final position (from -1 to 1) taking into account all the modifiers (deadzone, saturation, sensitivity, etc.). The calculated X and Y positions of the axes are retrieved by ComputedX and ComputedY properties. My Distance property is working well, but when I apply the sensitivity, the retrieved distance is less than 1 on diagonal directions if I move my josytick around, when it should be exactly 1, no matter the direction.īelow, I'm including a simplified version of my Joystick class, where I removed most of the unrelevant code.

My Joystick class has a Distance property, which retrieves the stick's distance from center (a value from 0 to 1). It seems to be working when the joystick direction is either horizontal or vertical, but when I move it to a diagonal direction, is seems buged. Right now, I already have my temporary fix which is not working very well. I want to apply circular sensitivity to the stick, but I don't really know how to do that, specially taking into account other calculations on the axes (like deadzone, distance from center, etc.). I applied sensitivity on a X-Box trigger without problems, but because a joystick has two axis (X and Y), I'm having trouble with the math involved. Sensitivity should make the joystick's distance from center non-linear. I'm having trouble with the mathematics of it, specifically with the sensitivity part. I'm working on a class that represents a stick of a gamepad.

How to calculate joystick sensitivity, taking into account deadzone and the circular nature of the stick?
