JISyed/Unity-XboxCtrlrInput

Setting controller Dead Zone

Closed this issue · 5 comments

xom0b commented

I've spent a while now digging through all of the inputs in the InputManager and can't seem to find which parameter changes the actual right stick dead zone when using the XCI.GetAxis(). If I call Input.GetAxis() then the dead zone is accurate but there are discrepancies between which controller Input thinks is the first player and which controller XCI thinks is the first player.

Hello,

The first thing I need to know is if you're making your game for Windows or macOS, because the right joystick axes are labeled differently on those platforms (I have no control over that).

To change the dead zone, go to the Unity Input Manager (Edit -> Project Settings -> Input). I realize the list of inputs is giant because they are mapped differently on different platforms.

On Windows, the X,Y axes for the right stick are Axis 4 and Axis 5, respectively. On macOS, they are Axis 3 and Axis 4, respectively. Linux is the same as Windows for the right stick. I derived this imformation from here.

Suppose you wanted to change the dead zone for a Windows game. You would go down the Input Manager and look for XboxAxis4Joy1 and XboxAxis5Joy1 for player 1 and modify the "Dead" value. For player 2, look for XboxAxis4Joy2 and XboxAxis5Joy2. For a single player game, look for XboxAxis4Joy0 and XboxAxis5Joy0.

For macOS, you would be looking for Axis3 and Axis4 instead of Axis4 and Axis5.

I hope that helps.

xom0b commented

I'm building the game on a windows machine aiming for a windows release. I've been able to figure all of that out but I want to change the Dead Zone for the XCI.GetAxis(), not the Input.GetAxis(). Right now I'm using a combination of both - using XCI.GetAxis() when I don't need something super precise and Input.GetAxis() when I need something precise. I use a switch statement checking the controller number using XCI.XboxController to make sure that player 1 is using XboxAxis4Joy1 and player 2 is using XboxAxis4Joy2.
The real problem here is that sometimes XCI and Input get switched up as to what they think is controller 1 and controller 2. Here is my code:

    _controllerLeftX = XCI.GetAxis(XboxAxis.LeftStickX, xcontroller);
    _controllerLeftY = XCI.GetAxis(XboxAxis.LeftStickY, xcontroller);
    _controllerRightX = XCI.GetAxisRaw(XboxAxis.RightStickX, xcontroller);
    _controllerRightY = XCI.GetAxisRaw(XboxAxis.RightStickY, xcontroller);
    _controllerA = XCI.GetButtonDown(XboxButton.A, xcontroller);
    _controllerB = XCI.GetButtonDown(XboxButton.B, xcontroller);

    switch (xcontroller)
    {
        case XboxController.First:
            _controllerPreciseRightX = Input.GetAxisRaw("XboxAxis4Joy1");
            _controllerPreciseRightY = Input.GetAxisRaw("XboxAxis5Joy1");
            break;
        case XboxController.Second:
            _controllerPreciseRightX = Input.GetAxisRaw("XboxAxis4Joy2");
            _controllerPreciseRightY = Input.GetAxisRaw("XboxAxis5Joy2");
            break;
        case XboxController.Third:
            _controllerPreciseRightX = Input.GetAxisRaw("XboxAxis4Joy3");
            _controllerPreciseRightY = Input.GetAxisRaw("XboxAxis5Joy3");
            break;
        case XboxController.Fourth:
            _controllerPreciseRightX = Input.GetAxisRaw("XboxAxis4Joy4");
            _controllerPreciseRightY = Input.GetAxisRaw("XboxAxis5Joy4");
            break;
    }`

Sometimes when I load the project, the XCI.GetAxis() will be reporting the correct value for controller 1, but when it hits the switch statement, the value reported from Input.GetAxis() is 0 - because it thinks the controller is controller 2. If I move controller 2's right stick, then the values are reported in XboxAxis4Joy1 and XboxAxis5Joy1 This is sometimes fixed by switching the controller's USB ports or reloading the Unity project.
If I can change XCI.GetAxis's deadzone I can stay away from the Input.GetAxis() controller discrepancies.

Thanks for the quick reply, I hope this helps clear up my problem.

I just released a new version of XboxCtrlrInput, which I think should solve the issue you were having.

The problem was that on Windows, XCI uses XInput instead of Unity's input API. Because of this, whatever deadzone values were defined in Unity's Input Manager were not being applied onto XInput's API (since it's 3rd party). I had to find a strange way to clone the Input Manager than write my own deadzone code to get it to work on Windows.

Update XboxCtrlrInput on your project and tell me if it works. Note that new files will be added to the project when you update.

If the problem persists, feel free to reopen this issue.

xom0b commented

It seemed to me that the after this update changing the input deadzone & cloning the input manager still didn't change the deadzone for the XCI.GetAxis calls. I was able to get it to work by changing line 1555 in the XboxCtrlrInput.cs script from

xInputCtrlrs[i] = GamePad.GetState(plyNum, GamePadDeadZone.IndependentAxis);

to

xInputCtrlrs[i] = GamePad.GetState(plyNum, GamePadDeadZone.Circular);