Artificial Intelligence

Recently, we’ve been desigining AI system for The Witcher. It’s different from previous systems I created, because they were usually mainly focused on combat. They were rather typical state machines with patrol/attack/chase/escape/etc states. This time, we focused mainly on everyday NPC behaviours, we want the player to feel like he’s in the middle of living world.

Basically, there are two extremes when it comes to modelling system like this (most of AI systems in games are somewhere inbetween). AI can be either totally emergent, where NPCs are free to do whatever they want to achieve their goals, or it can be scripted, so that our NPC Bob always go to the inn in the morning, drinks 2 beers there and then returns home.

Of course, at a first glance, former solution looks much more attractive and realistic. It quickly turns out, however, that it’s also very hard to debug, control and predict. As far as I can tell judging by press releases, Oblivion’s Radiant AI system uses such goal-driven system. If the NPC is hungry, he tries to find an action, which will let him satisfy his goal. If he has money, he may go and buy food, if he doesnt he may try to steal it, or perhaps steal the money first, then get food. It’s very unpredictable, tho. Sometimes it works very nice, in some cases it works very weird and not realistic (search the net for various AI videos, some of them are pretty funny).

Script based AI is more deterministic. In the most basic implementation, you just have scripts for certain NPC categories and they’re responsible for controlling their behaviour. It may look less “real” (Bob does same stuff every day), but it has its advantages. Apart from being easier to implement and debug, it has its impact on a gameplay as well. If you want to turn in a quest, you know where you can meet the NPC. Without going into details (game’s still in production, you know), AI in The Witcher is closer to emergent rather than scripted approach. When we first launched it, we had lots of problems with finding our NPCs, because they were doing their things in random places. In our system it can be controlled, so it’s easier now, but it’s also less stochastic obviously. Another thing is that, in many cases, it turns out that you want your NPCs to be “dumb”. For example, I want a bard in the inn to just stay there and sing. I dont need him to eat, go home, sleep, etc. I certainly dont want him to do any of this when player’s in the inn. Of course, it’s achievable in every system, but sometimes you forget about simple cases and it turns out that setting up a simple scenario like this still requires significant amount of work.

When you start implementing AI system for the first time, you quickly find many little issues that you didnt think about. What about actions with many participants, like conversations? What about tools? (should they appear/disappear magically, or maybe the NPC should have them at all times… or, ideally, he could pick them up). What about actions with pre/post animations? All of this needs to be solved. Then, when you finally implement all this, there’s still combat AI left, but it’s a topic of its own. In the meantime, if you’re interested, check out the GDC 2006 paper (Three States and a Plan: The A.I. of F.E.A.R.) by Jeff Orkin, it’s a fresh look on an old problem, I really liked it.

More Reading
Older// Hello, world!