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.

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 well | Movement, combat, stealth, crowd behavior | Open-ended conversation, flavour text, reacting to unusual player input |
| Running cost | Effectively zero, runs on the player’s device | Paid per request to a hosted model, or heavy hardware to run locally |
| Speed | Every frame, instantly | Noticeable delay while the reply is generated |
| Predictability | Fully predictable, easy to test | Can go off-script, contradict lore or break character |
| Designer control | Total | Shaped through prompts and guardrails, never total |
| Works offline | Yes | Only with a local model |
| Best fit | Almost every NPC in almost every game | A 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.





