French Design - A Technique For Eliciting Lifelike Behavior Using Simple Tools

Snipehunter's picture

I wanted to print an old design doc I'd written a few years ago, but sadly I haven't heard back from the studio I wrote it for, so I can't do that. Instead, I suppose I'll just talk about an idea I worked on once. Using the parlance of junk patents, let's call this installment of French Design - "A technique for eliciting lifelike behavior using simple tools."

I should probably start with a warning: This is going to be a largely inefficient way to do what I'm talking about, that's because of how generic it is. The point is to use nothing very simple tools- the technique can be applied in damned near any game.

Alright with all of that out of the way, let's talk about the goal: What we want to do here is make NPCs in the world behave as if they're intelligent beings when they aren't busy engaging with the player. We want them to do the things people would expect them to do, if no one was around. What they're actually doing depends heavily on the environment they're in, of course, but we'll get to that in a second.

First, let's talk about our tools. We're going to have to make a few assumptions as to what tools we have available, but it's a pretty simple list:

  1. The ability for each NPC in the "room" to independently track the value of 3 variables
  2. The ability for each of those variables to increment at a fixed rate, over time (e.g. "+1 per second")
    1. For added flair (not necessary): The ability to set these rates, per NPC.
  3. The ability for each NPC to locate and navigate to an object in the world
  4. An object in the world containing the following data:
    1. The animation or effect the object will play when it is interacted with
    2. The animation or effect the NPC will play, when it interacts with the object
      1. To do it right: The ability to orient and place the NPC correctly in relation to the object before any animations or effects are played.
      2. To do it well: A list, on the NPC, of which animations are valid for it to use.
    3. The values to add or subtract from each of an NPC's three variables when this object is interacted with

As you've probably guessed by now, what we're going to do here is encode some data in the world objects that tells NPCs how to use them (#4 on the list above). It's the first step towards building a system that will let an NPC which objects to use and it's also the way you message intelligence to the players. Basically, if you place a chair in the world, the chair contains something that says "hey NPC, here's how you sit on me." Since the animation is embedded in the object, any NPC in the world will now know how to "sit" on a chair even if they had no such ability, before. If you do it right, the NPC will even know where to put its backside and what direction to face when sitting. Despite this, if you do it well, only NPCs that it would make sense to see sitting around will ever use it.

Now our NPCs have their "smarts" - they how to logically handle the objects in the world around them when the time comes and since tool #3 on the list is the NPC's ability to find and get to those world objects, all that's left then is to figure out how to make the NPC decide what to do. That's where those three variables come in handy - it's time to use the first two tools on the list.

We'll start by giving each NPC the following imperatives:

  • If I'm not engaging the player, I want to find the object in the world that lowers the value of whichever of my three variables has the highest value.
    1. If there is a tie, I will randomly pick one of the tied variables.
    2. If I can't find an object, I will try again using the variable with the next largest value.
    3. If I have tried all three variables and can't find an object, I'll execute some default idle behavior.
  • Once I have found an object that qualifies I will move towards it and interact with it.

Believe it or not, all it takes for this to work now is to assign some values to the NPCs (Tool #1 on the original list and if you're going for added flair, the per-NPC rates mentioned in tool #2), place some NPCs and world objects in the world and turn it on. When you do, here's what will happen:

Your NPCs that aren't aware of the player will check the variables they maintain (let's call them X, Y and Z), pick the one with the largest value and move towards it to interact with it. Doing so will adjust the values of X, Y and Z for that NPC and when it's done interacting, that will matter when it decides what to do next. Those variables will also all be increasing by a fixed amount every second or every game tick (whatever your base of unit of time is).

So, you might be asking "why 3 variables and not 1?" And that's a valid question. After all, it's three times as much work for the NPC to go through when it decides what it wants to do, but having those three variables is pretty important to tuning the "smarts" of your NPCs. Those variables and the list of things each NPC can and can't do (if you implement that) represent two of the high-level "knobs" you can turn to tune how the room behaves.

For example, you could decide that X represents an NPC's desire to do work, Y represents an NPC's desire to slack off and Z represents a random element or chaos factor you add just for fun. Based on the idea that each variable represents a specific desire, you can set up NPCs to have their own personalities, which will be portrayed by their choice of what to interact with in the world. A chaotic NPC might increment Z at a faster rate than X or Y, for example, or a workaholic might never increment Y except as a result of using objects.

In other words, what we've put together here with our simple tools is a poor man's need based AI that runs in the background and makes the characters do something interesting when they'd otherwise be idle. Sure, there are a lot of holes in the system I laid out -- the most notable being that nothing is done to ensure two NPCs won't try to use the same object at the same time -- but the core of the system is sound and the edge cases aren't as numerous as you might think. Setting up the data can be a little time consuming, depending on your tools, but that really depends on your editors or apps, to be honest.

- Snipehunter

Technorati Tags:Technorati Tags: