Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | sixGdie |
Hi everyone, i’m learning some Godot and GDScript and i’m using Multiplayer Bomber one scripts but for a custom 3D game, i want to spawn 2 players but i can’t achieve it. How can i achieve spawn that players on multiple Position3D node in the scene ?
Here is the code from Multiplayer Bomber where players spawns:
remote func pre_start_game(spawn_points):
# Change scene.
var world = load("res://world.tscn").instance()
get_tree().get_root().add_child(world)
get_tree().get_root().get_node("Lobby").hide()
var player_scene = load("res://player.tscn")
for p_id in spawn_points:
var spawn_pos = world.get_node("SpawnPoints/" + str(spawn_points[p_id])).position
var player = player_scene.instance()
player.set_name(str(p_id)) # Use unique ID as node name.
player.position=spawn_pos
player.set_network_master(p_id) #set unique id as master.
if p_id == get_tree().get_network_unique_id():
# If node for this peer id, set name.
player.set_player_name(player_name)
else:
# Otherwise set name from peer.
player.set_player_name(players[p_id])
world.get_node("Players").add_child(player)
# Set up score.
world.get_node("Score").add_player(get_tree().get_network_unique_id(), player_name)
for pn in players:
world.get_node("Score").add_player(pn, players[pn])
if not get_tree().is_network_server():
# Tell server we are ready to start.
rpc_id(1, "ready_to_start", get_tree().get_network_unique_id())
elif players.size() == 0:
post_start_game()
Thanks in advance for the help !