2d multiplayer - need more than 2 players

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Pikado

i found this template for 2d multiplayer but it is made to work with only 2 players. what would i do to make it work with more players? i would like to have it spawn players based on how many people i have in a lobby (so if i have 2 players it would spawn 2 and if i have 5 it would spawn 5)

this is the template: Multiplayer 2D Platformer - Godot Asset Library

:bust_in_silhouette: Reply From: hinasis

By simple looking at it, it’s not prepared for dinamically add players, but you can try a few things:

First, add a list to the lobby to show connected players, and to avoid directly start the game after the first joined, an start game button.

For this to work, in the lobby script, trasnfer the game start capability from “player connected” method to the new “on start game button clicked” method you will create for the start game button, checking that at least 1 player joined the server.

And in the “on host pressed” method change the value that limits the peers connected, this line:

var err = host.create_server(DEFAULT_PORT,1) # max: 1 peer, since it's a 2 players game

Then in the stage scene and script, remove the player 2 in order to create it dinamically in a new method, one for each peer connected to server.

I’m sure I’m avoiding some details, but these are the basics.

:bust_in_silhouette: Reply From: Tova

i’ve used some stuff from bomber multiplayer demo and i think i managed to make it work