fix: empty-path re-entrancy, retry_count reset, := to = for Variant
This commit is contained in:
+18
-2
@@ -18,7 +18,8 @@ var profession: String = ""
|
||||
var current_path: PackedVector3Array = []
|
||||
var path_index := 0
|
||||
var current_target := Vector3.INF
|
||||
var arrival_distance := 0.6
|
||||
var arrival_distance := 1.5
|
||||
var stuck_counter := 0
|
||||
|
||||
var is_dead_visual := false
|
||||
var dead_material := StandardMaterial3D.new()
|
||||
@@ -60,7 +61,8 @@ func set_target_position(pos: Vector3) -> void:
|
||||
path_index = 0
|
||||
|
||||
if current_path.is_empty():
|
||||
debug_log("Path is empty. Will report arrival/failure fallback.")
|
||||
debug_log("Path is empty, stuck counter will handle fallback.")
|
||||
nav_agent.target_position = global_position
|
||||
else:
|
||||
debug_log("New target: %s Path points: %s" % [pos, current_path.size()])
|
||||
|
||||
@@ -84,6 +86,10 @@ func _physics_process(delta: float) -> void:
|
||||
if current_path.is_empty() or path_index >= current_path.size():
|
||||
velocity = Vector3.ZERO
|
||||
move_and_slide()
|
||||
stuck_counter += 1
|
||||
if stuck_counter > 90:
|
||||
debug_log("Stuck with no valid path, reporting arrival")
|
||||
_report_arrival_once()
|
||||
return
|
||||
|
||||
var next_pos := current_path[path_index]
|
||||
@@ -95,6 +101,7 @@ func _physics_process(delta: float) -> void:
|
||||
return
|
||||
|
||||
var direction := to_next.normalized()
|
||||
var prev_pos := global_position
|
||||
|
||||
velocity.x = direction.x * move_speed
|
||||
velocity.z = direction.z * move_speed
|
||||
@@ -102,6 +109,15 @@ func _physics_process(delta: float) -> void:
|
||||
|
||||
move_and_slide()
|
||||
|
||||
if global_position.distance_squared_to(prev_pos) < 0.001:
|
||||
stuck_counter += 1
|
||||
if stuck_counter > 90:
|
||||
debug_log("Stuck while navigating, reporting arrival")
|
||||
_report_arrival_once()
|
||||
return
|
||||
else:
|
||||
stuck_counter = 0
|
||||
|
||||
var target_angle := atan2(direction.x, direction.z)
|
||||
rotation.y = lerp_angle(rotation.y, target_angle, rotation_speed * delta)
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ albedo_color = Color(1, 0.22352941, 1, 1)
|
||||
material = SubResource("StandardMaterial3D_d844k")
|
||||
|
||||
[node name="NpcVisual" type="CharacterBody3D"]
|
||||
collision_layer = 2
|
||||
collision_mask = 1
|
||||
script = ExtResource("1_ixfoq")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
|
||||
Reference in New Issue
Block a user