Detection State MachineSimulation

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.

How detection state machine works in Godot

enumprimitive

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)

RayCast2Dnode

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)

Area2Dnode

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

Retro games that use detection state machine

4 catalogued game(s) use this mechanic, spanning 1983–1999.

Related simulation mechanics

▶ Explore Detection State Machine interactively — see every game + the Godot system