@@ -177,14 +177,7 @@ func _process(delta: float) -> void:
177177 else :
178178 guard_movement .stop_moving ()
179179 guard_movement .move ()
180- State .WAITING , State .DETECTING , State .INVESTIGATING :
181- guard_movement .move ()
182- State .RETURNING :
183- if breadcrumbs :
184- var target_position : Vector2 = breadcrumbs .back ()
185- guard_movement .set_destination (target_position )
186- else :
187- state = State .PATROLLING
180+ State .WAITING , State .DETECTING , State .INVESTIGATING , State .RETURNING :
188181 guard_movement .move ()
189182
190183 if state != State .ALERTED :
@@ -229,6 +222,8 @@ func _update_debug_info() -> void:
229222 match state :
230223 State .WAITING :
231224 debug_info .text += "%s : %.2f \n " % ["time left" , waiting_timer .time_left ]
225+ State .DETECTING , State .INVESTIGATING , State .RETURNING :
226+ debug_info .text += "%s : %s \n " % ["breadcrumbs" , breadcrumbs .size ()]
232227 _ :
233228 debug_info .text += "%s : %s \n " % ["previous_patrol_point_idx" , previous_patrol_point_idx ]
234229 debug_info .text += "%s : %s \n " % ["current_patrol_point_idx" , current_patrol_point_idx ]
@@ -244,6 +239,11 @@ func _on_destination_reached() -> void:
244239 state = State .WAITING
245240 State .RETURNING :
246241 breadcrumbs .pop_back ()
242+ if breadcrumbs :
243+ var target_position : Vector2 = breadcrumbs .back ()
244+ guard_movement .set_destination (target_position )
245+ else :
246+ state = State .PATROLLING
247247
248248
249249## What happens if the guard cannot reach their destination because it got
@@ -262,7 +262,10 @@ func _on_path_blocked() -> void:
262262 state = State .RETURNING
263263 State .RETURNING :
264264 if breadcrumbs :
265- breadcrumbs .pop_back ()
265+ var target_position : Vector2 = breadcrumbs .back ()
266+ guard_movement .set_destination (target_position )
267+ else :
268+ state = State .PATROLLING
266269
267270
268271func _set_state (new_state : State ) -> void :
0 commit comments