extends CharacterBody3D var movement_speed: float = 3.0 var angry_meter: int = 5 var target: CharacterBody3D @onready var timer: Timer = $Timer var skip: bool = false @onready var navigation_agent: NavigationAgent3D = $NavigationAgent3D func _ready() -> void: if Networking.isManager: if timer.timeout.connect(_timer_done) != OK: Log.error("FAILED to connect the timeout signal to _timer_done!", "Internal Error: Failed to connect signal.") first_frame.call_deferred() func _timer_done() -> void: if angry_meter > 0: Log.debug("angrier %d" % angry_meter) angry_meter -= 1 else: timer.stop() first_frame() func first_frame() -> void: await get_tree().physics_frame timer.start() actor_setup(999999999) # determines the closest player and navigate. func actor_setup(lowest_distance: float) -> void: for child: Node in get_tree().root.get_node("/root/"+Game.mapname+"/").get_children(): if child is Node3D: if child.has_method("playerstub") and position.distance_to((child as Node3D).position) < lowest_distance: target = child navigation_agent.set_target_position(target.position) func _physics_process(_delta: float) -> void: if Networking.isManager and angry_meter == 0: actor_setup(position.distance_to(target.position)) if navigation_agent.is_navigation_finished(): return var current_agent_position: Vector3 = global_position var next_path_position: Vector3 = navigation_agent.get_next_path_position() velocity = current_agent_position.direction_to(next_path_position) * movement_speed if move_and_slide(): pass Networking.npc_sync_call(position, rotation, name)