@@ -88,7 +88,7 @@ var current_patrol_point_idx: int = 0
8888## returning to patrol, the guard walks through all these positions.
8989var breadcrumbs : Array [Vector2 ] = []
9090## Current state of the guard.
91- var state : State = State . PATROLLING :
91+ var state : State :
9292 set = _set_state
9393
9494var _previous_state : State
@@ -162,6 +162,13 @@ func _ready() -> void:
162162 guard_movement .destination_reached .connect (self ._on_destination_reached )
163163 guard_movement .path_blocked .connect (self ._on_path_blocked )
164164
165+ # Wait 2 frames before starting to match backwards compatibility.
166+ await get_tree ().process_frame
167+ await get_tree ().process_frame
168+
169+ _advance_target_patrol_point ()
170+ state = State .WAITING
171+
165172
166173func _process (delta : float ) -> void :
167174 _update_debug_info ()
@@ -170,14 +177,7 @@ func _process(delta: float) -> void:
170177 return
171178
172179 match state :
173- State .PATROLLING :
174- if patrol_path :
175- var target_position : Vector2 = _patrol_point_position (current_patrol_point_idx )
176- guard_movement .set_destination (target_position )
177- else :
178- guard_movement .stop_moving ()
179- guard_movement .move ()
180- State .WAITING , State .DETECTING , State .INVESTIGATING , State .RETURNING :
180+ State .PATROLLING , State .WAITING , State .DETECTING , State .INVESTIGATING , State .RETURNING :
181181 guard_movement .move ()
182182
183183 if state != State .ALERTED :
@@ -276,6 +276,9 @@ func _set_state(new_state: State) -> void:
276276 state = new_state
277277
278278 match state :
279+ State .PATROLLING :
280+ var target_position : Vector2 = _patrol_point_position (current_patrol_point_idx )
281+ guard_movement .set_destination (target_position )
279282 State .DETECTING :
280283 if not _alert_sound .playing :
281284 _alert_sound .play ()
0 commit comments