Skip to content
RED SAGSkills
mediumGame Developer interview question

How would you build the AI for an enemy guard that patrols, notices the player, chases and attacks?

What the interviewer wants to hear

  • State machine or behaviour tree for decisions
  • Perception: sight cone with dot product and line-of-sight raycast, hearing
  • Navigation mesh for movement
  • Tuning values exposed to designers
  • Performance: update AI less often for far enemies

Model answer

I would use a behaviour tree or a simple state machine with states like Patrol, Suspicious, Chase, Attack and Return. For perception, the guard checks if the player is within view distance, uses a dot product to see if the player is within the view cone, and then raycasts to confirm line of sight is not blocked by walls. Noise events, like footsteps, can make the guard suspicious and investigate. Movement uses a baked navigation mesh, with patrol points placed by designers. Values like view angle, reaction time and chase speed are exposed so designers can tune them without code. For performance, guards far from the player update perception less often, and I use the engine tools like Unreal Behavior Trees and EQS where they fit.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium Game Developer questions