Local Multiplayer with Gamepads? <SOLVED>

0 favourites
  • 7 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Making a local multiplayer game where the controls for each player are the exact same. It seems silly to copy and paste the same code over and over for each controller changing the gamepad number. Is there anyway to pass the Gamepad Index to a function parameter? Something like Call "Accelerate" (Gamepad.Index) right now I am having to make 4 calls for every player which is cumbersome.

  • You can loop through all gamepads in a loop:

    For "n" from 0 to (NumberOfPlayers-1)
    	Gamepad loopindex Button A is down...
    
    
  • That seems to work really well but breaks down if there is only one player left on the board. So I took out the -1 portion so the four loop can never be equal to 0 with at least 1 player on the board. I'm not sure how efficient it is to be continuously running these for loop checks, but if it gets to be to much I will just switch back to triggers on button pushes. Thanks for the help it is much appreciated.

  • Gamepad index is zero-based, so if you only have one player, the loop should run from 0 to 0. For two players from 0 to 1, and so on.

    Running this loop on every tick should not have any noticeable impact on performance.

  • I believe I found the issue with the for loop. Initially it will work fine but lets say player 4 (index 3) kills player 1. So now the for loop is only looping through 3 players indexed 0-2 and player 4 (index 3) who is still alive will never show up in the for loop, thus his controller inputs never get recognized. It also could be that I am off base and not implementing you idea correctly.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • First, I suggest making just one loop and check all buttons inside of it.

    .

    You need to link players with their gamepads. You can add an instance variable GamepadNo to the player sprite. When a button is pressed on gamepad #1, pick a player with GamepadNo=1 and control it.

    .

    Or you can do this with an array, for example X-index of the array is the player number, and the value is gamepad number. So for 4 players your array may look like this:

    x=0: 3
    x=1: 0
    x=2: 2
    x=3: 1
    

    You fill this array at the start of the game, when you ask each player to press a button on their gamepads. Then in the game when a button is pressed on gamepad with index 1, you know that it belongs to player #3.

  • I believe I got it working, by removing the player.count-1 bit and just putting a hard 3 in there. I also set everything into a single loop instead of multiples like you suggested. Thanks for all the help you always post on my stuff and get me out of a bind.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)