I got multiplayer working occasionally on the Lobby scene nut it doesn’t always work, maybe I should force it to only work on the server and rpc to actually add the Player?
set_multiplayer_authority(name.to_int()) # doesn't always work correctly
# https://forum.godotengine.org/t/multiplayer-authority-not-being-set-correctly/40437/3
#call_deferred("set_multiplayer_authority", name.to_int()) # works worse
Guess it’s back to the original demonstration that works quite well. I assume that things will work if I don’t overload the connection with information. Example: The chat functionality always works.
Clearly there are demos that show a websocket chat application and guides to use ENetfor LAN Multipplayer but it does not allow for using servers or addresses.
This was wasted effort since not even forcing the server works every time and the Camera occasionally updates when it shouldn’t:
func add_player(id: int, char : Node3D = null):
if char == null and multiplayer.is_server():
var pick = randi_range(0, CHARACTERS.size() - 1)
var character = load(CHARACTERS[pick]).instantiate()
CHARACTERS.remove_at(pick)
#CHARACTERS.remove_at(pick)
# Set player id.
character.player = id
# Randomize character position.
var pos : Vector3 = character.position
character.position = Vector3(pos.x + randf_range(-2, 2), 0, pos.y + randf_range(-2, 2))
character.name = str(id) # Mulyiplayer Spawner does this
if randf_range(0, 1) > 0.5:
character.flip = true
if randf_range(0, 1) > 0.5:
character.flip = true
$Players.add_child(character, true)
rpc('add_player', id, character)
if id == 1:
character.get_node('Camera3D').call_deferred('make_current')
else:
rpc_id(id, 'set_camera', character)
else:
if char.player != id:
$Players.add_child(char, true)
func set_camera(character):
if character.player != 1:
character.get_node('Camera3D').call_deferred('make_current')
I see, after re-reading and some searching I got it, only the server spawns and adds/removes players, I exagerated, both the MultiplayerSpaner and MultiplayerSynchronizer handle the rest so I have to get out of their way instead of re-doing what they do (replic<ate everything on all peers).