feat: add completition of work only after work is done
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
signal arrived_at_target(sim_id: int)
|
||||
|
||||
const DEBUG_LOGS := false
|
||||
|
||||
@export var move_speed := 3.0
|
||||
@@ -8,6 +10,7 @@ const DEBUG_LOGS := false
|
||||
|
||||
@onready var nav_agent: NavigationAgent3D = $NavigationAgent3D
|
||||
|
||||
var has_reported_arrival := false
|
||||
var sim_id: int = -1
|
||||
var npc_name: String = ""
|
||||
var profession: String = ""
|
||||
@@ -30,6 +33,24 @@ func set_target_position(pos: Vector3) -> void:
|
||||
if current_target.distance_to(pos) < 0.1:
|
||||
return
|
||||
|
||||
current_target = pos
|
||||
has_reported_arrival = false
|
||||
nav_agent.target_position = pos
|
||||
|
||||
await get_tree().physics_frame
|
||||
|
||||
current_path = NavigationServer3D.map_get_path(
|
||||
get_world_3d().navigation_map,
|
||||
global_position,
|
||||
pos,
|
||||
true
|
||||
)
|
||||
|
||||
path_index = 0
|
||||
debug_log("New target: %s Path points: %s" % [pos, current_path.size()])
|
||||
if current_target.distance_to(pos) < 0.1:
|
||||
return
|
||||
|
||||
current_target = pos
|
||||
nav_agent.target_position = pos
|
||||
|
||||
@@ -50,6 +71,12 @@ func _physics_process(delta: float) -> void:
|
||||
if current_path.is_empty() or path_index >= current_path.size():
|
||||
velocity = Vector3.ZERO
|
||||
move_and_slide()
|
||||
|
||||
if not has_reported_arrival and current_target != Vector3.INF:
|
||||
has_reported_arrival = true
|
||||
debug_log("Arrived at target")
|
||||
arrived_at_target.emit(sim_id)
|
||||
|
||||
return
|
||||
|
||||
var next_pos := current_path[path_index]
|
||||
|
||||
Reference in New Issue
Block a user