Further improved NPC logic, and made it multiplayer friendly.

This commit is contained in:
Patrick_Pluto 2024-12-12 11:59:22 +01:00
parent 1ca0a2bdc0
commit 1ee6f6cc6d
5 changed files with 56 additions and 57 deletions

View file

@ -280,3 +280,17 @@ func player_sync(position: Vector3, rotation: Vector3) -> void:
var player: CharacterBody3D = get_node("/root/"+Game.mapname+"/"+peer)
player.position = position
player.rotation = rotation
func npc_sync_call(position: Vector3, rotation: Vector3, node_name: String) -> void:
for peer: int in Networking.get_ids():
if peer != multiplayer.get_unique_id():
if rpc_id(peer, "npc_sync", position, rotation, node_name) != OK:
Log.warning("Couldn't send RPC to %d!" % peer)
# Synchronizes the npc state.
@rpc("any_peer", "call_local", "reliable")
func npc_sync(position: Vector3, rotation: Vector3, node_name: String) -> void:
if managerID == multiplayer.get_remote_sender_id():
var npc: CharacterBody3D = get_node("/root/"+Game.mapname+"/"+node_name)
npc.position = position
npc.rotation = rotation