How do you control your NPCs?

I’m just starting to think about NPC movement. My present feeling is that an NPC should first explore an area and ‘remember’ the location of key features/areas. Sorta look around first and ‘say’ “oh, there’s a door over there and a window over here.” Identify areas of danger and areas of safety. And NPCs should be doing something, task/goal driven. I hate how, in some RPGs, the NPCs are always in the same spot doing the same thing. Its a little different in Oblivion, the NPCs seem to follow a time table. But I killed a shop/bar owner once and the waitress just kept moving around and even walked over the corpse. That doesn’t seem right. I noticed in some games, the patrols will notice a change. If a door, once closed, is now open or if a light is broken they will comment/act on it.

I hope this can be a broad discussion. Maybe compile a list of ways that NPCs can be controlled and site games that use that method. I’m new to this. I know some buzzwords like scripting, pathfinding, and waypoints but no real code to support it. How were the bots in Pac Man controlled? Does anyone have python code for this?

And maybe we can list websites that give sample code and such. I found a paper earlier tonight that presents an interesting take on NPC perception. Documents/WPG1Perception.pdf

1 Like

I’m interested in doing this as well. I have begun coding these sorts of things and I think the best thing would be to use Event Handlers:

This way when a light bulb breaks it could send a message out saying it’s broke so all other objects in the world could react to it. You could also set a task to have the message get sent out so many seconds or minutes so that other NPCs will notice it.

I came across an intereting website.

The Suffering: A Game AI Case Study

Working Group on Rule-based Systems

Generation of Emotional Behavior for Non-Player Characters
– Development of EmoBot for Quake II –

Just wanted to say thanks to Brian et al for posting these links. Good reading!

1 Like

Efficient, Realistic NPC Control Systems using Behavior-Based … … lexbot.pdf

For more information on FlexBot, including a download of the latest
version, see … nloads.htm

An Introduction to Game AI

“…games like MechWarrior. They use goal-based engines - each entity within the game is assigned a certain goal, be it ‘protect base’, ‘attack bridge’, ‘fly in circles’. As the game world changes, so do the goals of the various entities.”

Simple Board Game AI
Influence Mapping

Finite State Machine Tutorial … torial.asp

“the purpose behind states is to replace the need for IF/THEN statements with events.”

This article actually includes some code (working code), but its in C++. The FSM code has also been ported to both Java and Rebol.

How To Get Started with Gaming AI

Memory in Games
“…instead of covering each move combination or pattern (and have about 20 page of code), we could use an algorithm that would use memory of previous game so it wouldn’t make the same mistakes over and over again (and use about 20 lines of code).”

Smart Moves: Intelligent Path-Finding
" To demonstrate the workings of the algorithms visually, I have developed a program in Delphi 2.0 called “PathDemo.” It is available for readers to download. "

Also contains sample code for Breadth-first search, Dijkstra’s algorithm, and A*. See Listings 1-3 in the article.

I’d like to dive deeper into the quake code and look at the AI portion to get some ideas.

Quake source code released under the GPL, links for engine and game code:

* Engine Code: [](
* Game & Tool Code: [](

Very interesting information about AI: … eprog.html - Amit’s Game Programming Information - Game AI for Developers

Alive! is a sandbox for learning AI and game programming. It’s a simple IDE inspired by Self and Squeak but written in Python.

Analyzing the AI Bot Library from the Quake 3 Source Code

Area Awareness System
Routing With Caching
Stack-Based Goal Architecture
Main AI Routine

An Overview of the AI Architecture Inside the F.E.A.R. SDK

“The codebase is in C++, like the rest of the AAA games industry, but the code is written in a style that should provide valuable insights for the developers among you using C# or Java.”

“Download the AI source code from the SDK in this thread of the forum.”

Examining the AI Scripts in Call of Duty 4’s Developer Tools

“one of the best examples of scripted level design.”

“…205,718 lines of level scripts (not including the automatically generated configuration files”