I’ve bought a Godot Multiplayer course (in early access) and can’t fix issue with client spawn. It’s spawning wrong, I know that problem with authority in player’s script, it’s not giving permission to change his position, but how to fix it?)
I have Node2D called SpawnPoint, which has 2 child-nodes, instead of spawning on second spot, client is spawning on (0,0) position
extends CharacterBody2D # player.gd
var owner_id = 1
func _enter_tree() -> void:
owner_id = name.to_int()
set_multiplayer_authority(owner_id)
if owner_id != multiplayer.get_unique_id():
return
set_up_camera()
extends Node2D # level.gd
@export var player_scene: PackedScene
@onready var players_container: Node2D = %PlayersContainer
@onready var spawn_points: Node2D = %SpawnPoints
var next_spawn_point_index = 0
func _ready() -> void:
if !multiplayer.is_server():
return
Lobby.player_disconnected.connect(delete_player)
for id in multiplayer.get_peers():
add_player(id)
add_player(1)
func add_player(peer_id):
var player_instance = player_scene.instantiate()
player_instance.position = get_spawn_point()
player_instance.name = str(peer_id)
players_container.add_child(player_instance)
func get_spawn_point() -> Vector2:
var spawn_point = spawn_points.get_child(next_spawn_point_index).position
next_spawn_point_index += 1
if next_spawn_point_index >= spawn_points.get_child_count():
next_spawn_point_index = 0
return spawn_point
Players synchronized, all is working OK, issue is only with spawning, thanks!)