flixel icon indicating copy to clipboard operation
flixel copied to clipboard

FlxGamepad's axis deadzone checking doesn't work properly with analogue sticks

Open twincannon opened this issue 12 years ago • 5 comments

If you set a deadzone in FlxGamepad, it prevents any motion from registering until the axis is greater than the deadzone. This works fine for a single axis, i.e. a trigger button.

However, when trying to use an analogue stick with a deadzone set, the deadzone is handled for each axis individually, which means you can have the stick pushed past the deadzone on one axis, but it still checks on another. This results in large portions of the stick's outer range of motion that can't be accessed.

I.e., if you set a gamepad's deadzone of 0.5, you can only register input on the gamepad < 0.5 regardless of axis.

Hard to explain, so I made a quick demo because haxeflixel is amazing! https://dl.dropboxusercontent.com/u/154355/permalink/deadzonebug.swf (the gamepad input works in firefox but not chrome for me) source: http://pastebin.com/4TFXKfxK

Expected functionality would be for an analogue stick's axis to ignore the deadzone if it's other axis is already pushed past it, or make it work via a radius.

Tested with both flash and windows compiles with an xbox controller.

twincannon avatar Jun 13 '14 06:06 twincannon

Very good point, I agree that this is not really ideal. Also, thanks a lot for making that demo! :)

The problem here is that a gamepad doesn't really know what its axes are (let alone what gamepad type it is, OpenFL doesn't provide a way to check that yet). There's only an array of axes, and you tell the gamepad the ID of the value you want. For this to work, getXAngle() and getYAngle() would both require you to pass the IDs to both axes.

Gama11 avatar Jun 13 '14 07:06 Gama11

Yeah... I took a look around the code but I couldn't think of any sensible clean way of handling it. :/

Fortunately it's not too awful hard to work around. But the default deadzone is 0.15 and it should probably be changed to 0 until this is improved (I thought my controller was broken for a bit with how it was acting :P)

As a workaround I'm just doing this:

m_gamePad.deadZone = 0.0;
var xaxis = m_gamePad.getXAxis( XboxButtonID.RIGHT_ANALOGUE_X );
var yaxis = m_gamePad.getYAxis( XboxButtonID.RIGHT_ANALOGUE_Y );

var vecAxis = new FlxVector( xaxis, yaxis );
var length = vecAxis.length;

//deadzone
if ( length < 0.3 )
    xaxis = yaxis = 0;

twincannon avatar Jun 13 '14 07:06 twincannon

Well, the user shouldn't have to work around this sorta thing. :)

This will require some breaking API changes to work properly... but so be it. I have some ideas on how a fix could look like, I'm going to give the implementation a try later.

Gama11 avatar Jun 13 '14 08:06 Gama11

We could make deadzone a property that does a vector length check on both axis.

gamedevsam avatar Jun 13 '14 14:06 gamedevsam

@gamedevsam How does that make sense? The deadzone doesn't know about the axes that are being checked.

I've just finished implementing a fix for this actually, but I'm not sure these circular deadzones are the way to go (in all cases). Take this piece of code in mode for example (updated to the new API for getYAxis() and getXAxis():

if (gamepad.getXAxis(OUYAButtonID.LEFT_ANALOGUE_STICK) < 0)
{
    moveLeft();
}
if (gamepad.getXAxis(OUYAButtonID.LEFT_ANALOGUE_STICK) > 0)
{
    moveRight();
}

if (gamepad.getYAxis(OUYAButtonID.LEFT_ANALOGUE_STICK) < 0)
{
    moveUp();
}

if (gamepad.getYAxis(OUYAButtonID.LEFT_ANALOGUE_STICK) > 0)
{
    moveDown();
}

The problem is that when moving the analogue stick left, either the up or down ifs will also trigger. This is pretty logical, since you're practically circumventing the deadzone in y-direction by moving it in x-direction. A y value of 0.001 is still enough to trigger the > 0 checks. This is not desirable in this case.

I'm thinking something along the lines of this is the way to go: support several deadzone modes, Circular and IndepedantAxes. The latter should probably be the default? Not sure...

Gama11 avatar Jun 13 '14 14:06 Gama11