daemon3000 / InputManager

Custom InputManager for Unity
Other
587 stars 88 forks source link

GetButtonDown returns true for all PlayerIDs #22

Closed oservieres closed 8 years ago

oservieres commented 8 years ago

First, a big thank you for this project, which helped me a lot with my local-crossplatform-multiplayer proof of concept ! It really prevents a huge pain in the ass for me.

Unfortunately, I think I have a problem. Until now, I only used Axis inputs like sticks and triggers of the xbox 360 controller. It worked like a charm. But now, I wanna use the buttons. And it feels like the input manager cannot detect which plays presses a given button.

Here is my input manager conf :

image

Here is my input configuration : image

Now, I have this very small script in an empty game object on my scene :

    void Update() {
        PlayerID[] players = new PlayerID[] { PlayerID.One, PlayerID.Two, PlayerID.Three, PlayerID.Four };
        foreach(PlayerID playerId in players) {
            if (TeamUtility.IO.InputManager.GetButtonDown("Jump", playerId)) {
                Debug.Log(playerId.ToString());
            }
        }
    }

Now, in test mode, when I press the Jump button on my first controller, I expect this trace :

One

But here is what really happens :

One
Two
Three
Four

I am new to unity, I may be doing something wrong.

Thank you in advance !

daemon3000 commented 8 years ago

The Joystick property only affects axis input(sticks and triggers). For buttons you have to use Joystick1Button0, Joystick2Button0, etc. If you use JoystickButton0 it will listen for input from all gamepads. This is the way it works with Unity's built-in input manager so I kept it the same.

Do you think I should take into account the Joystick property? For example, if you set the joystick to Joystick 1, should I let you introduce only Joystick1ButtonX in the Positive and Negative fields? Would this make it easier to work with and more clear?

oservieres commented 8 years ago

Thank you for your fast answer ! I will run some tests based on your first paragraph tonight, I will keep your informed. If I understand well what you said, it should work like a charm.

And maybe I was mislead by the Xbox360 controller template. I will give you some feedback if it's the case.

oservieres commented 8 years ago

And it works perfectly well !

As I said, I have been mistaken by the joystick mappings that can be imported: they do not mention the controller IDs. So I said to myself "okay, the manager has a layer of abstraction here, no need to give the joystick ID".

It's not a big deal to add the ID in each button. Personnaly I would not to touch anything (also it could cause BC break), and add some documentation or a new sample scene. Maybe it already exists and I missed it ?

daemon3000 commented 8 years ago

Personnaly I would not to touch anything (also it could cause BC break), and add some documentation or a new sample scene. Maybe it already exists and I missed it ?

It works the same way as Unity's input manager so I didn't mention in the documentation. I didn't consider it necessary. What I'm probably going to do is show a warning in the input editor if you use JoystickButtonX instead of the one with the joystick ID.

daemon3000 commented 8 years ago

You now get a warning in the input editor if you use JoystickButtonX instead of the one with the joystick ID.