i’m making a multiplayer game, and i’ve been following this tutorial. my problem is that i tried to move the host and join buttons into their own scene, and now non-hosts can’t move around. the host can move around just fine and everyone can join and see that, but they just can’t move themselves. i tried disabling all of my animation code and getting rid of collision shapes, but nothing really works. anyone know what to do here? i’m using godot 4.3.
use a port number higher than 1024, anything below is privileged
don’t open the project twice, just run multiple instances under “Debug” tab
non-authority clients are still calling move_and_slide() since they forgot to indent
The world script’s _ready() should only run on the host, adding players only if clients connect to the host.
extends Node2D
func _ready() -> void:
if multiplayer.is_server():
multiplayer.peer_connected.connect(MultiplayerManager.add_player)
MultiplayerManager.add_player() # and this is problematic
Another issue is MultiplayerManager adding players to the wrong node; Your multiplayer spawner is set to the World node, but MultiplayerManager will add players to children of itself, not the world. No clear solution to this outside of moving the MultiplayerManager code into “World”
I would recommend against a global “Multiplayer Manager” since Godot already handles what needs to be global, globally, and what it doesn’t, shouldn’t; like spawning, shouldn’t be global. Your host and join functions should be moved on the main menu, for reference the multiplayer variable is already shared with other nodes in a pseudo global way.
that all fixed it! thanks for the tips, i didn’t know multiplayer was kinda global so that helps a lot. you responded just as i began to separate my code into a multiplayer branch and continue to develop without multiplayer, so perfect timing. don’t have to do that anymore