0 Favourites

Multiple, dynamic gamepads

  • Hi folks, I'm running into a brick wall here and I hope some of the more experienced C2 users can give me some insight into how to fix this issue. Here's my situation:

    • Four-player co-op game, using keyboard and/or gamepads.
    • Character selection screen before the game kicks off.
    • In this screen, I want to give players the chance to pick up any gamepad and press A to join in. I want them to be assigned a player number based on the order in which they join.

    I've got the game working so that player numbers are assigned based on the controller number, so P1 can be keyboard, P2 can be gamepad(0), P3 is gamepad(1), etc. Or P1 is gamepad(0), P2 is gamepad(1) and so on. All of the controls are set up so that it accepts input from any source, then passes that input along to a set of generic functions that actually make the players move.

    The trouble is, there's no generic "On any gamepad, any button pressed" event, nor is there a way to record a controller number when a button is pressed. This means that players will need to join the game in the order that gamepads are assigned by the OS, not the order in which they press the A button. This is what I'm trying to avoid.

    I'd like to use the logic "When Up is pressed on controller(Player/ControllerNumber), move Sprite(Player/ControllerNumber) up", but I can't figure out how to match a player to a controller in a dynamic way.

    I hope this makes sense, and I hope someone can assist!

  • Hello GeometriX

    I ran into the same problems as you and I got a solution working, maybe not the better

    You create your players with an ID (starting at 0 for first player) and you assign this player an input method (like Keyboard or Gamepad)

    You loop over all of you players, and test the input corresponding to the input method and the gamepad number and you save the input in a Player variable called "Input" using "setbit" like in this tutorial: https://www.scirra.com/tutorials/915/multiplayer-tutorial-3-real-time-game/page-6

    For gamepad

    For keyboard

    In the same loop you get the input using the same input variable and the "getbit" expression

    And voilà :]

  • You could create 4 events (on gamepad 1 pressed, 2, 3, etc ) that checks which "start" button was pressed, then assign that player an ID. Also make a variable that gets assigned the gamepad number who's button was pressed.

    Then create one function for all of your inputs. You pass the button that was pressed (gamepad.lastbutton) And you pass the gamepad number that presseed it (the variable from before)

    there fore each time a button is pressed, the function uses who pushed it and which button, then updates the associated player with whatever he's supposed to do. (Pick by evalulate, player.ID = function.param(0))

    then you only have one function, to handle all player movement etc for all players, thus only having to write it once.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Also make a variable that gets assigned the gamepad number who's button was pressed.

    That's the exact problem. I've already got controls working across all gamepads and keyboard for pre-selected controller/player pairs, but there's no "Gamepad.Number" or whatever expression. That's why I can't figure how to dynamically assign the controller.

    EDIT: Sorry, I misunderstood your first point. I've done that now which is great. Assigned controllers initially is now resolved. But this still doesn't solve the issue in your second paragraph "And you pass the gamepad number that presseed it (the variable from before)". There's no way to extract that from a gamepad event without having events for every single gamepad and passing along the variable manually.

    Thanks for your reply as well, RootKernel, but, unless I'm missing something, it doesn't help solve my problem.

    Really what would solve all of my issues is if there was an action "On any gamepad pressed" (maybe a set of actions, for buttons/sticks/etc.), and a Gamepad.Number expression that reads which gamepad triggered the current event. Then I could bundle all of my controls and assignments into just a few events.

    @Ashley, any thoughts on this? I know that there probably is a way around my problem, but I can't quite manage to bend my brain there. Having a couple of conditions and an expression would be magical.

  • Ooookay, I get it now. I was way over-thinking this whole thing, which was causing my to misinterpret what both of you were saying.

    Thanks so much RootKernel and justifun, I really appreciate your help!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
107 13,191
LeuNoeleeste's avatar
LeuNoeleeste
Unread hot topic Locked topic
78 38,323
Ashley's avatar
Ashley Construct Team Founder
Unread hot topic
0 Favourites
[Effect] : 2D Dynamic Lighting
69 44,465
totoe's avatar
totoe