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.
More medium Game Developer questions
- Your game runs at 40 FPS but must hit 60 FPS. How do you find and fix the problem?
- How would you design a save game system?
- How would you choose between Unity, Unreal and Godot for a new project?
- How do you make game systems easy for designers to tune without changing code?
- How would you build a third-person camera that follows the player smoothly and does not clip through walls?
- Players report that their character sometimes falls through the floor. How do you investigate and fix it?
- How would you design input handling that supports keyboard, gamepad and touch, plus key rebinding?
- How would you procedurally generate dungeon levels that are always playable?
- Describe how you would design a reusable object pool and what trade-offs it has.