Enemies cycle through named awareness states (unaware / suspicious / alert / searching) based on sensory input from the player.
The guard's AI runs an explicit state machine — patrol, suspicious, alert (it gives chase), then search the last-seen spot before resetting.
The named states (UNAWARE / SUSPICIOUS / ALERT / SEARCHING) and the transition rules between them are the mechanic. Everything else is just feeding the transitions.
enum S { UNAWARE, SUSPICIOUS, ALERT, SEARCHING }
var state = S.UNAWARE
func transition(to): state = to; on_enter(to)Sight input. A clear ray to the player raises a suspicion meter; sustained sight pushes the state toward ALERT.
if sees_player():
suspicion += delta
if suspicion > 1.0: transition(S.ALERT)Sound input. Noises inside the hearing radius bump the state toward SUSPICIOUS or send an ALERT guard to SEARCHING at the noise origin.
func _on_noise(pos):
last_noise = pos
if state == S.UNAWARE: transition(S.SUSPICIOUS)In short: State machine on each enemy node; RayCast2D for sight; Area2D for sound radius; state transition rules check both inputs
4 catalogued game(s) use this mechanic, spanning 1983–1999.
▶ Explore Detection State Machine interactively — see every game + the Godot system