fix: a lot of network sync fixes

This commit is contained in:
DottsGit
2026-06-06 20:45:10 -04:00
parent dbbfbef4a4
commit 07a15fe998
8 changed files with 179 additions and 91 deletions
+35 -13
View File
@@ -16,6 +16,7 @@ var health: float = 100.0
var max_shield: float = 100.0
var shield: float = 100.0
var time_since_last_damage: float = 0.0
var death_count: int = 0
var is_dead: bool = false
# UI
@@ -325,13 +326,16 @@ func _spawn_remote_projectile(origin: Vector3, fire_dir: Vector3, weapon_name: S
if camera:
var wman = camera.get_node_or_null("WeaponManager")
if wman:
var target_weapon = null
for w in wman.weapons.values():
if "weapon_name" in w and w.weapon_name == weapon_name:
if w.has_method("_spawn_custom_projectile"):
w._spawn_custom_projectile(origin, fire_dir)
return
# Fallback if weapon not found (e.g. joined late and weapons didn't build yet)
target_weapon = w
break
if target_weapon and target_weapon.has_method("_spawn_custom_projectile"):
target_weapon._spawn_custom_projectile(origin, fire_dir)
return
# Generic fallback if weapon not found (e.g. joined late and weapons didn't build yet)
var proj = Node3D.new()
proj.name = "RemoteProjectile"
@@ -825,17 +829,16 @@ func die(impulse: Vector3 = Vector3.ZERO) -> void:
col.set_deferred("disabled", true)
# Spawn true physics ragdoll
death_count += 1
var ragdoll = load("res://characters/procedural_ragdoll.gd").new()
ragdoll.name = "Ragdoll_%s_%d" % [self.name, death_count]
ragdoll_instance = ragdoll
get_tree().current_scene.add_child(ragdoll)
ragdoll.global_transform = global_transform
ragdoll.build_ragdoll(Color(0.2, 0.4, 0.8)) # Blueish player color
# Wait a frame for physics to initialize then apply velocity
get_tree().create_timer(0.01).timeout.connect(func():
if is_instance_valid(ragdoll):
ragdoll.apply_initial_velocities(velocity, impulse)
)
get_tree().create_timer(0.01).timeout.connect(_apply_ragdoll_velocity.bind(ragdoll, velocity, impulse))
# Move camera to 3rd person view using SpringArm3D
if is_instance_valid(camera):
@@ -900,6 +903,10 @@ func die(impulse: Vector3 = Vector3.ZERO) -> void:
death_screen.visible = true
set_process_input(true)
func _apply_ragdoll_velocity(ragdoll: Node3D, l_vel: Vector3, imp: Vector3) -> void:
if is_instance_valid(ragdoll):
ragdoll.apply_initial_velocities(l_vel, imp)
func _input(event: InputEvent) -> void:
if not is_multiplayer_authority(): return
if is_dead and death_screen and death_screen.visible:
@@ -908,11 +915,26 @@ func _input(event: InputEvent) -> void:
_on_respawn_pressed()
func _on_respawn_pressed() -> void:
var spawn_pos = Vector3(randf_range(-5, 5), 5, randf_range(-5, 5))
if not multiplayer.has_multiplayer_peer() or multiplayer.multiplayer_peer is OfflineMultiplayerPeer:
rpc_respawn(spawn_pos)
else:
if multiplayer.is_server():
var spawn_pos = Vector3(randf_range(-5, 5), 5, randf_range(-5, 5))
rpc_respawn.rpc(spawn_pos)
else:
rpc_request_respawn.rpc_id(1)
@rpc("any_peer", "call_local", "reliable")
func rpc_request_respawn() -> void:
if not multiplayer.is_server():
return
var sender_id = multiplayer.get_remote_sender_id()
if sender_id != 1 and sender_id != str(name).to_int():
return
if is_dead:
var spawn_pos = Vector3(randf_range(-5, 5), 5, randf_range(-5, 5))
rpc_respawn.rpc(spawn_pos)
else:
# Deal 9999 damage to trigger the full death sequence locally and over the network
take_damage(9999, global_position, null, Vector3.ZERO)
@rpc("any_peer", "call_local", "reliable")
func rpc_respawn(spawn_pos: Vector3) -> void: