AI NPC/Enemy Agents

The Core Idea: Scoring, Not State Machines

Prodigy's AI doesn't use a traditional state machine. Instead, every tick, every action the Agent is assigned to use will score itself based on current conditions in the context. The highest scorer wins and drives the NPC that frame. There's no explicit "switch to chase state" — chase simply outscores everything else when the conditions are right.

This means behavior is emergent and composable: you tune scores and conditions, not transitions.

The Tick Loop

Every frame, the AI does four things:

  1. Sense: The sensor scans and updates perception data

  2. Score: Every action in the NPC's action list returns a number; highest wins

  3. Execute: The winning action tells the Motor where to move, what to aim at, whether to fire

  4. Output: The Motor builds final input and hands it to Locomotion.

No unique AI components needed past this point, any Agent should be controllable by AI if they use the standard component stack - same for players.

The Default Actions

Some default actions are provided, but you can easily add more and configure behavior. The included actions are sufficient to do basic AI behavior.

A higher scoring action always takes precedence over lower scoring ones. If Chase (60) and Attack (50) are both valid, Chase wins until the agent closes range, then Attack takes over naturally as Chase's score will fall out when the conditions for "chasing" are finally met.

What You Configure Per NPC

Everything lives on a ProdigyAgentAiDefinition instance for each unique NPC that you want. You can configure them in Vault Dashboard very easily. There you can find parameters that will affect the Personality, Awareness, Timing, Combat Feel and Vision.

What the AI "Knows" (Memory)

Each NPC has a persistent AiMemory object that survives across ticks. The Memory class can be extended to include more things as needed for your project needs. You don't want to store transient runtime data in DataEntity instances. The Memory class contains stuff like:

  • CurrentTarget: who they're focusing on, or fighting

  • IsProvoked: have they ever seen an enemy this encounter

  • LastSeenTargetPosition: where the target was when last visible

  • OriginPosition: where the agent started

etc..

Patrol Routes

Attach an AiPatrolRoute component to a GameObject in the scene with waypoints placed as child transforms. Assign it to the NPC's AgentPlacement component. The Patrol Action will follow the route in Loop or PingPong mode, waiting at each waypoint for a configurable duration.

Patrol only runs when the NPC has no target, combat always overrides it because of how the scoring system works.

Last updated