Godot Version
4.3
Question
I have a 3D multiplayer game utilizing a lot of the code from the Godot High Level Multiplayer docs.
My server, that can also be a client or Player, spawns the Players here on the Root Game Node with this script:
#ROOT GAME NODE SCRIPT#
#Server is running all of this ONLY I know this because in the script before where it calls start_game() I am checking multiplayer.is_server()#
func start_game():
for player_id in Lobby.players:
spawn_player(player_id)
func spawn_player(authority_id: int):
var player = player_scene.instantiate()
player.name = "Player" + str(authority_id)
add_child(player)
player.global_transform.origin = Vector3(0,0,0)
player.set_multiplayer_authority(authority_id)
It is also setting the authority as you can see. Then the MultiplayerSpawner Node is supposed to replicate the Player across all Clients right?
Well, the authority is all messed up and I am unable to play/control each individual client when testing with multiple Debug Instances.
Here is where I am trying to remedy this in my Player code:
#PLAYER SCRIPT#
func _ready():
if multiplayer.is_server():
self.set_multiplayer_authority(1)
else:
self.set_multiplayer_authority(multiplayer.get_unique_id())
if not is_multiplayer_authority():
return
anim_player.playback_default_blend_time = 0.3
camera.current = true
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
#rest of player code below here
I just know I am missing something small with the authority and can’t put my finger on it… I feel like the camera should be assigned correctly, but it just isn’t working. I can control 1 instance and not the other.
Here’s to hoping this makes sense and I am wanting to say my main problem is that maybe the MultiplayerSpawner just doesn’t save and replicate the authority as I think it should across clients?
Here are my MultiplayerSpawner settings for reference:
- Root node of the level is Sandbox
- I only want 4 Players to ever be able to spawn (testing with only 2 instances right now)
- My Player.tscn is referenced correctly