Gamepad Deadzone

Hi,

I am using a gamepad to control the movement and direction of my sprite.
My problem is that when I let go of the analog stick, my character turns to a random angle.
This is how I am determining the angle of my sprite:

r = Math.PI / 2 + Math.atan2(gamepad.getYLeft(), gamepad.getXLeft());

Thanks,
novasharp

So what library are you using for the gamepad ? they have usually functionality for this.
Although I can say, it often happens due to overused controllers… my ps2 controller will do the same in every game, I have to fiddle around

Why rely on hardware when you can fix it with code?


final float deadZone = ...;

float dx = gamepad.getYLeft();
float dy = gamepad.getXLeft();
if(dx*dx+dy*dy > deadZone*deadZone) { // sqrt(dx^2 + dy^2) > deadZone
   r = Math.PI / 2 + Math.atan2(dy, dx);
}

I am using JInput.

the Gamepad class that I am using is just a quick wrapper around it to find the first gamepad and get the values from it.