Are NPCs AI? Scripted vs LLM Characters Explained

By Arron R.10 min read
How smart are NPC AI systems? Almost every NPC runs on game AI: scripts, state machines and behavior trees that only look intelligent. A newer wave adds languag

How smart are NPC AI systems, and are NPCs AI in the first place? The short answer is yes, but almost never the kind of AI you are probably picturing. An NPC (non-player character, any character in a game that a human player does not control) is run by “game AI,” a broad label for the code that makes characters move, fight, flee and talk. For most of gaming history that code has been hand-written rules. Only recently have some games started connecting characters to large language models so you can type anything and get an in-character reply. This guide explains both kinds, how they compare, and how to build each into your own game.

What does “AI” mean when we talk about NPCs?

In game development, “AI” has always meant something looser than it does in a research lab. As the Wikipedia overview of AI in video games puts it, game AI covers a wide range of techniques borrowed from computer science, control theory and robotics, and its goal is believable, fun behavior rather than genuine reasoning or learning. Plenty of what gets called NPC AI is a fixed set of responses to a fixed set of inputs.

That is not a criticism. The classic example is Pac-Man. Each ghost has its own targeting rule, so they feel like they have personalities, and they switch between a “chase” mode and a “scatter” mode where they retreat to their corners. None of the ghosts think. They follow a few lines of logic. Yet players have described them as cunning for over four decades.

So when you ask whether NPCs are AI, the honest answer has two parts:

  • Yes, by the industry’s definition. Any code that decides what a computer-controlled character does is called AI in game development.
  • No, by the everyday definition. Most NPCs do not understand anything, do not learn while you play, and could not hold a conversation outside the lines a writer prepared.

The same Wikipedia article notes that marketing often describes scripted behavior as if it showed personality or creativity. When a trailer says enemies “adapt to your tactics,” that usually means a designer anticipated those tactics and wrote a response.

How smart are NPC AI systems today?

NPC brains sit on a spectrum. Knowing where a given technique falls helps you pick the right one for your own game, because smarter is not automatically better.

Scripts and patterns

The oldest approach: the character follows a predetermined path or sequence. Early arcade enemies moved in stored patterns. Scripted cutscene characters still work this way today.

Finite-state machines

A finite-state machine (FSM) gives the character a small set of states, such as idle, patrol, chase and attack, plus rules for switching between them. FSMs became standard in the 1990s as new genres demanded more complex behavior. They are still the first thing most developers reach for, because they are fast, predictable and easy to debug.

Behavior trees and utility AI

A behavior tree organises decisions as a branching tree that the game checks every few frames: “Am I hurt? Then find cover. Otherwise, can I see the player? Then attack.” Utility AI scores every possible action numerically and picks the highest score, which produces more varied behavior. Most modern action games use one of these, sometimes both.

Planning and machine learning

Goal-oriented planners let a character work out a sequence of actions to reach a goal, like “get the key, open the door, ambush the player.” Machine learning shows up mostly in racing lines, testing bots and animation rather than in the decision-making of shipped characters, because learned behavior is hard to control and tune.

Language models

The newest layer: a large language model (LLM, the same family of tech behind chatbots) generates what a character says, sometimes with a memory of past conversations. This is what most people mean today when they talk about “AI NPCs.” It is the first technique on the list that can produce replies nobody wrote in advance.

Spectrum of NPC AI techniques from simple scripts to language models
Most NPCs sit on the left side of this spectrum, even in big modern games.

Scripted vs LLM-driven NPCs: how they compare

Both approaches have a place. Here is how they stack up on the things that matter when you ship a game.

Classic game AI (FSM, behavior tree)Language-model NPC
What it does wellMovement, combat, stealth, crowd behaviorOpen-ended conversation, flavour text, reacting to unusual player input
Running costEffectively zero, runs on the player’s devicePaid per request to a hosted model, or heavy hardware to run locally
SpeedEvery frame, instantlyNoticeable delay while the reply is generated
PredictabilityFully predictable, easy to testCan go off-script, contradict lore or break character
Designer controlTotalShaped through prompts and guardrails, never total
Works offlineYesOnly with a local model
Best fitAlmost every NPC in almost every gameA few key characters where conversation is the gameplay

The pattern you see in mods and indie experiments, including the community mods that bring LLM chat to big open-world RPGs such as Skyrim, is a hybrid. The game’s existing AI still decides where the character walks and whether it attacks. The language model only takes over the dialogue. That split keeps the game stable while making conversations feel alive.

How a classic NPC brain works (with JavaScript code)

To see how ordinary NPC intelligence really is under the hood, here is a complete state machine for a guard who patrols, chases the player when they come close, and walks home when they escape. It is plain JavaScript, so you can drop it into a Phaser, Three.js or vanilla canvas game and call it once per frame.

const guard = {
  state: "patrol",
  x: 0,
  home: 0,
  patrolRange: 100,
  sightRange: 120,
  speed: 1.5,
  dir: 1,
};

function updateGuard(npc, player) {
  const dist = Math.abs(player.x - npc.x);

  switch (npc.state) {
    case "patrol":
      npc.x += npc.dir * npc.speed;
      // Turn around at the edge of the patrol zone
      if (Math.abs(npc.x - npc.home) > npc.patrolRange) {
        npc.dir = Math.sign(npc.home - npc.x) || 1;
      }
      if (dist < npc.sightRange) npc.state = "chase";
      break;

    case "chase":
      npc.x += Math.sign(player.x - npc.x) * npc.speed * 2;
      // Give up if the player gets far enough away
      if (dist > npc.sightRange * 1.5) npc.state = "return";
      break;

    case "return":
      npc.x += Math.sign(npc.home - npc.x) * npc.speed;
      if (Math.abs(npc.x - npc.home) < 2) npc.state = "patrol";
      if (dist < npc.sightRange) npc.state = "chase";
      break;
  }
}

// In your game loop:
// updateGuard(guard, player);

About 30 lines, and a player will describe this guard as “alert” and “persistent.” Notice the small design choice in the chase state: the guard gives up at 1.5 times its sight range, not at the sight range itself. That gap (called hysteresis) stops the guard from flickering between chase and return when the player stands right on the edge. Tiny touches like this are most of what makes game AI feel smart.

If you want a longer walkthrough of building a talking character from scratch, see our guide on how to build an AI powered NPC with JavaScript.

What changes when you plug in a language model

Adding an LLM to a character is easy to prototype and hard to do well. The safest structure keeps the state machine in charge of actions and lets the model only speak. Here is a dialogue function that follows that rule:

async function npcSay(npc, playerLine) {
  const system =
    `You are ${npc.name}, a ${npc.role} in a fantasy village. ` +
    `Your current mood: ${npc.state}. ` +
    `Facts you know: ${npc.facts.join("; ")}. ` +
    `Reply in one short sentence, in character. Never mention being an AI.`;

  try {
    // Your own server holds the API key; never call the model from the browser directly
    const res = await fetch("/api/npc-chat", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ system, message: playerLine }),
    });
    if (!res.ok) throw new Error("Bad response");
    const data = await res.json();
    return String(data.reply).slice(0, 200);
  } catch (err) {
    // Fall back to a hand-written line so the game never stalls
    const lines = npc.fallbackLines;
    return lines[Math.floor(Math.random() * lines.length)];
  }
}

Four things in that snippet do the heavy lifting:

  1. State goes into the prompt. The model knows the guard is chasing you, so its line fits what the player sees on screen.
  2. Facts are injected, not assumed. The model only “knows” what you pass in. This is the simplest form of NPC memory, and it is how you stop characters inventing lore.
  3. The key lives on a server. Any API key shipped in browser code can be read by players and abused.
  4. There is always a fallback. Network errors, rate limits and slow replies happen. The NPC should still say something.

The usual trade-offs of language-model NPCs are real: processing cost, latency and loss of control. A combat enemy that waits a second for a model to decide whether to swing a sword is unplayable. A shopkeeper who takes a second to answer a strange question feels natural. Choose where the model goes accordingly.

Hybrid NPC design with a state machine for actions and a language model for dialogue
The hybrid pattern: code decides what the NPC does, the model only decides what it says.

Building NPCs for your own game with WizardGenie

If you have read this far, you probably want more than a definition. You want characters in your own game. The cleanest route in Sorceress is WizardGenie, the AI-native game engine at the heart of the suite. A game engine is the software framework that supplies the core systems a game runs on, such as rendering and input, so you are not rebuilding them for every project. With WizardGenie, you describe the game you want, and it writes, runs and iterates on the code. It runs on the web with nothing to install, and as a Windows desktop app with an auto-updater that adds native file access and longer agent sessions.

That makes it a practical fit for NPC work, because NPC behavior is exactly the kind of logic that is tedious to hand-write and easy to describe. A workflow that suits beginners:

  1. Describe the behavior, not the code. Something like: “Add a village guard who patrols between the well and the gate, chases the player on sight, gives up when the player is far away, and walks back to his post.” That is a state machine in plain English.
  2. Play it and refine in words. “He gives up too fast” or “make him slower when returning” is a valid next instruction. This is the loop known as vibe coding: you steer by results rather than by reading every line.
  3. Add dialogue last. Once the guard behaves well, ask for a talk interaction with a fallback list of lines. If you then want language-model dialogue, ask for the server-side pattern shown above.
  4. Pick the model that fits the job. WizardGenie works with the leading AI coding models, and you can switch models with your own API key.

Characters also need to look and sound like someone. That is where the rest of Sorceress comes in. Auto-Sprite v2 creates game-ready 2D sprites for any character and any animation in any art style, so your guard can have walk and attack cycles that match his states. For 3D projects, 3D Studio turns a typed idea into a rigged, animated, game-ready 3D character. For a voice, Sound Studio covers AI music, sound effects and text-to-speech with voice cloning, which is handy for recording a set of fallback barks.

If you prefer another coding agent, the Sorceress API gives WizardGenie, Cursor, Claude Code or Codex one key to generate sprites, 3D models, rigs, animation, music and SFX. The full list of tools lives in the Sorceress tools guide.

A note on scope: a small indie team wins by making a handful of characters memorable, not by simulating a whole city. One well-written talking innkeeper beats fifty generic chatbots.

Mistakes people make with AI NPCs

  • Using a language model for decisions. Letting the model choose combat actions or quest outcomes makes your game slow, expensive and impossible to balance. Keep decisions in code.
  • No fallback dialogue. The first outage turns your NPC into a frozen statue. Always write a few backup lines.
  • Unlimited conversation length. Long chat histories cost more per request and drift off character. Summarise or trim memory, and cap reply length.
  • Shipping keys in the client. Route every model call through a server you control.
  • Making everyone talk. Open conversation with every villager dilutes the special characters and multiplies costs. Reserve it for characters where talking is the point.
  • Overbuilding the brain. Players judge intelligence by what they see. Good animation, a reaction sound and a well-timed line often read as smarter than a complex planner, so polish the feedback before you add more logic.
  • Ignoring tone. Generated lines that feel generic quickly get labelled as low-effort AI content by players. Give each character a specific voice, a few quirks and a narrow set of facts.

The verdict

Are NPCs AI? They always have been, in the game-industry sense: code deciding what a character does. What has changed is that a new layer, language models, can now give some characters open conversation. The best designs treat these as two tools for two jobs. Classic game AI (state machines, behavior trees, utility scoring) handles everything a character does, cheaply and predictably. A language model, used sparingly and with fallbacks, handles what a few key characters say.

For your own project, start with a state machine, get the behavior feeling right, then decide whether any character truly benefits from free conversation. WizardGenie can write both layers from a plain description, and the asset tools in Sorceress give those characters a face and a voice. If you are new to building games, our beginner’s guide to video game development is a good next read.

Frequently Asked Questions

Are NPCs AI or real people?

NPC stands for non-player character, so by definition no human controls it. Its behavior comes from code the developers wrote. In most games that code is classic game AI: rules, state machines and pathfinding. Some multiplayer games include bots that imitate players, and a few newer games connect characters to language models, but in every case the character is software, not a person typing replies.

Do modern games use ChatGPT-style AI for NPCs?

A small but growing number do, mostly for dialogue. A language model writes what the character says, while traditional game AI still handles movement, combat and quest logic. Large commercial games remain cautious because model calls add latency, running costs and the risk of a character saying something off-script. Mods and indie experiments have moved faster than big studios here.

What games have AI NPCs you can talk to freely?

Free-form conversation shows up mainly in three places: community mods for big open-world RPGs such as Skyrim that route character dialogue through a language model, small indie and experimental games built around talking to characters, and tech demos. Mainstream releases still lean on written dialogue trees, sometimes with generated lines layered on top for ambient chatter.

Can I add AI NPCs to my own indie game?

Yes. Start with a simple state machine for behavior, which costs nothing to run and is easy to debug. If you want open conversation, add a language model only for dialogue, called through your own server so your API key stays private, with a fallback line for when the call fails. An AI game engine such as WizardGenie can write this code from a plain description.

Are AI NPCs expensive to run?

Classic NPC AI is nearly free: it runs locally on the player’s device every frame. Language-model NPCs cost money per request because each reply is a call to a hosted model, unless you run a small model locally, which needs capable hardware. Keeping replies short, limiting how often characters talk and caching common answers keeps costs manageable.

Sources

  1. Artificial intelligence in video games — Wikipedia
  2. Game engine — Wikipedia
  3. Vibe coding — Wikipedia
  4. Indie game — Wikipedia
Written by Arron R.·2,253 words·10 min read

Related posts