fix: a lot of networking bugs

This commit is contained in:
DottsGit
2026-06-06 19:26:22 -04:00
parent ff3e01a9e5
commit dbbfbef4a4
7 changed files with 194 additions and 109 deletions
+34 -19
View File
@@ -293,25 +293,40 @@ func _spawn_player(pid: int) -> CharacterBody3D:
# Use a slightly random spawn position to avoid exact overlapping
player.position = Vector3(randf_range(-2, 2), 2.0, randf_range(-2, 2))
# Network Synchronizer
var sync = MultiplayerSynchronizer.new()
sync.name = "MultiplayerSynchronizer"
sync.set_multiplayer_authority(pid)
var rep_config = SceneReplicationConfig.new()
rep_config.add_property(":position")
rep_config.add_property(":rotation")
rep_config.add_property("HeadPivot:rotation")
rep_config.add_property(":synced_movement_state")
rep_config.add_property(":synced_movement_speed")
rep_config.add_property(":synced_is_crouching")
rep_config.add_property(":synced_weapon_path")
rep_config.add_property(":synced_loadout_p1")
rep_config.add_property(":synced_loadout_p2")
rep_config.add_property(":synced_loadout_sp")
rep_config.add_property(":synced_loadout_melee")
rep_config.add_property(":synced_loadout_ready")
sync.replication_config = rep_config
player.add_child(sync)
# Server Synchronizer (Host is the ground truth)
var server_sync = MultiplayerSynchronizer.new()
server_sync.name = "ServerSynchronizer"
server_sync.set_multiplayer_authority(1) # Host always controls these
var server_rep_config = SceneReplicationConfig.new()
server_rep_config.add_property(":position")
server_rep_config.add_property(":synced_movement_state")
server_rep_config.add_property(":synced_movement_speed")
server_rep_config.add_property(":synced_is_crouching")
server_rep_config.add_property(":health")
server_rep_config.add_property(":shield")
server_rep_config.add_property(":is_dead")
server_rep_config.add_property(":synced_grapple_point")
server_rep_config.add_property(":synced_is_grapple_shooting")
server_sync.replication_config = server_rep_config
player.add_child(server_sync)
# Client Synchronizer (Client dictates their aim and loadout setup)
var client_sync = MultiplayerSynchronizer.new()
client_sync.name = "MultiplayerSynchronizer" # Keep original name for compatibility if needed elsewhere
client_sync.set_multiplayer_authority(pid)
var client_rep_config = SceneReplicationConfig.new()
client_rep_config.add_property(":rotation")
client_rep_config.add_property("HeadPivot:rotation")
client_rep_config.add_property(":synced_weapon_path")
client_rep_config.add_property(":synced_loadout_p1")
client_rep_config.add_property(":synced_loadout_p2")
client_rep_config.add_property(":synced_loadout_sp")
client_rep_config.add_property(":synced_loadout_melee")
client_rep_config.add_property(":synced_loadout_ready")
client_rep_config.add_property(":synced_is_targeting")
client_rep_config.add_property(":synced_homing_target_pos")
client_sync.replication_config = client_rep_config
player.add_child(client_sync)
# Collision shape
var col_shape := CollisionShape3D.new()