@@ -84,8 +84,6 @@ const DEFAULT_SPRITE_FRAMES = preload("uid://ovu5wqo15s5g")
8484var previous_patrol_point_idx : int = - 1
8585## Index of the current patrol point.
8686var current_patrol_point_idx : int = 0
87- ## Last position in which the player was seen.
88- var last_seen_position : Vector2
8987## Breadcrumbs for tracking guards position while investigating, before
9088## returning to patrol, the guard walks through all these positions.
9189var breadcrumbs : Array [Vector2 ] = []
@@ -179,12 +177,7 @@ func _process(delta: float) -> void:
179177 else :
180178 guard_movement .stop_moving ()
181179 guard_movement .move ()
182- State .WAITING :
183- guard_movement .move ()
184- State .DETECTING :
185- guard_movement .move ()
186- State .INVESTIGATING :
187- guard_movement .set_destination (last_seen_position )
180+ State .WAITING , State .DETECTING , State .INVESTIGATING :
188181 guard_movement .move ()
189182 State .RETURNING :
190183 if breadcrumbs :
@@ -476,10 +469,12 @@ func _on_detection_area_body_entered(body: Node2D) -> void:
476469
477470func _on_detection_area_body_exited (body : Node2D ) -> void :
478471 _player = null
479- last_seen_position = body .global_position
480472 if state == State .DETECTING :
481473 guard_movement .stop_moving ()
482474 state = State .INVESTIGATING
475+ guard_movement .set_destination (body .global_position )
476+ elif state == State .INVESTIGATING :
477+ guard_movement .set_destination (body .global_position )
483478
484479
485480func _on_waiting_timer_timeout () -> void :
0 commit comments