Skip to content

Commit db37166

Browse files
committed
Guard script: Do INVESTIGATING state change only once
1 parent b5fcc35 commit db37166

File tree

1 file changed

+4
-9
lines changed
  • scenes/game_elements/characters/enemies/guard/components

1 file changed

+4
-9
lines changed

scenes/game_elements/characters/enemies/guard/components/guard.gd

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ const DEFAULT_SPRITE_FRAMES = preload("uid://ovu5wqo15s5g")
8484
var previous_patrol_point_idx: int = -1
8585
## Index of the current patrol point.
8686
var 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.
9189
var 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

477470
func _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

485480
func _on_waiting_timer_timeout() -> void:

0 commit comments

Comments
 (0)