Godot Version
4.2.1 (4.1+)
Questions
I’m trying to make custom MultiplayerSynchronizer and I have a few questions
-
1 Am I doing it right?
Here is my players spawn function:func add_player(peer_id: int) -> Node3D: var new_player := PLAYER_SCENE.instantiate() as CharacterBody3D if !new_player: printerr('Player scene error'); return new_player.peer_id = peer_id new_player.name = str(peer_id) new_player.set_multiplayer_authority(peer_id) new_player.get_node('multiplayer_synchronizer').set_multiplayer_authority(peer_id) players_node_3d.add_child(new_player) return new_player
And this is the synchronization script:
extends MultiplayerSynchronizer @onready var player: CharacterBody3D = $'..' var player_head: Node3D var is_ready := false var _lerped_position := Vector3.ZERO var _lerped_rotation := Vector3.ZERO @rpc('any_peer', 'call_remote', 'unreliable') func rpc_sync(pos: Vector3, rotation: Vector3) -> void: if !is_ready: return _lerped_position = lerp(_lerped_position, pos, 0.85) player.position = _lerped_position _lerped_rotation = lerp(_lerped_rotation, rotation, 0.9) player_head.rotation.x = _lerped_rotation.x player.rotation.y = _lerped_rotation.y func _enter_tree() -> void: set_process(false) visibility_update_mode = MultiplayerSynchronizer.VISIBILITY_PROCESS_NONE func start() -> void: _lerped_position = player.position _lerped_rotation = player.rotation visibility_update_mode = MultiplayerSynchronizer.VISIBILITY_PROCESS_IDLE if 1: player_head = player.head if !player_head: return is_ready = true if player.is_authority: set_process(true) func _exit_tree() -> void: set_process(false) visibility_update_mode = MultiplayerSynchronizer.VISIBILITY_PROCESS_NONE func _process(_delta: float) -> void: rpc_sync.rpc(player.position, Vector3(player_head.rotation.x, player.rotation.y, 0.0))
-
2 Do I even need to write code above in synchronizer or just in some 3d node? And do I need give it authority?
Everything works great but I have a doubts about synchronization