Making Them Move: Game AI & NPC Systems

#unity

Architecture

1. Spawner GameObject

Placed manually at doorsteps (or wherever). Each one controls a schedule for spawning NPCs.

Spawner Script Responsibilities:

  • Timer to spawn NPCs at intervals (fixed or randomized)
  • Keep track of active NPCs if you want to limit total (e.g. max # per spawner)
  • Reference an NPC prefab to instantiate

2. NPC Prefab

  • Includes NavMeshAgent for walking
  • Has an Animator with a blend tree or simple state machine
  • Uses root motion or syncs movement speed with NavMeshAgent
  • References a "behavior" script for pathing and actions

> Don't forget to install the tools!

Unity package manager installing the AI Navigation tools

3. Movement Target System

Use Checkpoint GameObjects in the scene (like path targets or nav anchors).

Options:

  • Tag them ("NPCTarget")
  • Place them under a parent (/NPCCheckpoints/)
  • Use a ScriptableObject list if you want dynamic ones per scene

Each NPC picks random ones to walk to and idles there, then picks another.


Network Considerations

  • NPCs should only be spawned on the server

  • NPC movement should be synced with position + animation (use Mirror NetworkTransform or custom sync if you want tight control)

  • Avoid syncing pathfinding logic client-side

    --