Saturday, April 13, 2013

Dumbass #1

A scary amount of time and energy has always went to the graphical part of T22. And probably that counts for most other hobby or commercial games out there as well.... Only to found out your graphics are outdated a few months later again, when CryEngine 7 or UnrealEngine 6 billion releases. Kinda pathetic. And worse, you would almost forget about other elements in your game. Such as making a fun game.

So, between repainting the T22 corridors and programming other cosmetic features, it was time to pick up an old dusty AI modul. AI, what does that mean again? Oh yes, Artificial Intelligence. One of the 2013 targets is to play with monsters. Not scripted ones, but monsters that actually think, follow you, make (the right) decisions in a given context, and scare the player out of the damn building. And in case we don't have a cool looking animated monster by then, we just use our "Stickman":

isn't he awesome?

I have to admit that I'm not very familiar with making AI yet. Of course I've heard, read and played before with pathfinding, state machines, world awareness and fuzzy logic... and that's exactly what AI is to me; fuzzy.

Though AI might not be as large the graphical system, it's a tricky one. Not very strange if you realize how little we know about our own brains. You can walk to a Döner Kebab corner and buy a snack. But how come you know the route (or not)? What do you do to avoid getting killed in your little journey to that cafeteria? When and how late do you go? And for Döner sake, why?

Well you can fill in some answers here. Varying from simple scenarios, to utterly complicated ones. You know the route, cause you've heard about it and know the place globally. You can read signs, and smell roasted lamb + garlic sauce when approaching. You don't get killed cause you don't cross the roads if there are cars nearby. And you avoid dark alleys with man eating hobo’s. So for nothing special. But now it comes. It's 02:30 in the night, not a common time to score some food unless you're drunk-hungry. But in this case, you didn't get drunk or anything. Nah, your girl left you for the 12th time and she doesn’t answer the phone anymore. You can’t sleep so the only logical choice is to go out and eat Döner.

Bladibla. The good thing about games is that you don't need such complex scenarios usually (and otherwise you just script them), because the average game-foe doesn't live long enough to reach diner. Enemy soldier? Bang, bang, headshot, dead. Incoming monster crawling on the ceiling?! Rocket blast! Two arms, one leg and three eyeballs flying around. Just another day in game land, one of the most violent places in the virtual world.

Because of that rapid pace, human-like activities such as sleeping, eating, operating a device, or chatting with another NPC are fairly simple and often 100% scripted. That doesn't mean that acting like a human (or animal, or monster, or alien, or ...) isn't important. If all foes would just stand still waiting until you enter the scene, the AI would be predictable, and appear very "computerish". And boring. Shooting aliens that were taking a dump in Duke Nukem was more fun than stirring up the neighborhood filled with "statue" monsters, waiting on your appearance. Immersion has become crucial in games, so the general advice is to let each enemy do *something* when not fighting you. However, as I was trying to explain, because of the tempo and short lives, just a single scripted sequence per NPC is usually enough to let the player think something useful is happening in that military camp, factory, or city. Let them rest, tinker a car wheel, chat, walk circles, whatever.

One of the awesome surprises in Half life was the arrival of soldiers. A welcome variation on the dumber alien opponents. Compared to other games of that time, the soldiers appeared really smart and "human like". Not that they studied at Harvard, but their manouvres, (scripted) events and endless noisy "Bravo Zulu, Sector clear" radio chats made them appear "smart".

Instead of making a drama soap, most engines focus the AI on giving the player a hard time. That means shooting, chasing, hiding, seeking cover, and eventually doing teamwork (let a few guys give cover fire while another flanks you). This involves path-finding (= able to find you without getting stuck in a wall or drowning in a river), shooting and sensing you. These last two elements are kinda funny though. I'll explain.

Computers cheat. No matter how much Punkbuster software you install, your CPU enemies will always know your exact location, see you though a thick layer of foliage, and fire their guns 100% accurate 1 nanosecond after they saw you. It’s not their fault though. Computer foes were born in shared RAM memory, thus having telepathic powers, and are driven by a processor that doesn't make mistakes. Computers don’t doubt, it’s either yes or no. And it happens they decide very, VERY quickly.

But obviously, a game where the AI can find you in a maze and shoots immediately, isn't fun. Players must be given a fair chance, and experience a learning curve as they get better and better in exploiting AI weaknesses. Why else would you play a game?! So, it's up to the programmers to "dumb down" the enemies. In (shooter) games this is often done by reducing the enemy accuracy, delaying their ear & eye sensors, and/or just by giving the player a ridiculously long health bar so it will survive attacks. But this still makes the AI a bit, you know, inhuman. Instead of applying cheap tricks, AI programmers look more and more to replicate actual human behavior. They mask the 100% accurate (cheating) computer capabilities with a layer of clumsy, fuzzy, stupid human logic.

A computer enemy losing his gun and surrender, yeah right. As if the CPU gives a shit about his virtual life. Yet seeing this for the first time in (N64) Perfect Dark was another step closer to more realistic AI.

Humans think and handle way different than a computer. A computer uses exact numbers, coordinates and yes/no conditions. Humans on the other hand base their actions on experiences stored in your upper-harddisc. Hand in toaster = ouch! = not good. So don’t touch it. Hand in girlfriend = ... never mind. The brain is a blurry archive of audiovisual memoires. If we see or hear something, we connect it (megafast) with certain memories. This brings us in a mood, let us do things, warns us, pleases or annoys us, et cetera.

Doing this learning process in a game would be tedious though. Besides, your opponents usually don't get a chance to learn anyway. If they don't react "smart" right away, they'll be dead. So instead we give the AI a set of functions that apply on the game. Call it Instinct. Being able to find cover, to reload a gun, or to close in without running through the open field. Or, to kick back a ball in case of a Soccer game. Shooters are a classical example to explain AI as the opponents need tactics, but of course there are other types of games as well.

Graphics slowly getting a bit better in this corridor. Now put some AI in it...

About that, Tower22 monsters won't exactly be Power Rangers. They won't be dodging bullets since you won't be firing a lot (if at all), neither do they fire back. They don't operate in large teams, and from an ugly monster you can't expect genius behavior anyway. Well... what can they do then?! Uhm... walking. Maybe climbing or swimming. Sneak up on you. Use the environment against you (yes, that sounds interesting). Sleep. Eat (you).

Sounds easy. And yes, compared to shooters with soldiers, this game won't be on the cutting edge when it comes to AI. I admit. But that doesn't make the monster behavior less challenging though. They will "shine" in different ways. For one thing, T22 monsters actually do have a long live so using simple scripted animations just before you storm in a room, are a no-no here. They have act “useful” in the T22 world instead of just wandering around. And they have to do it in a freaky, spooky, scary way. And yep, that’s difficult. Maybe not in programming terms, but from an artistic horror perspective, it is a challenge. A monster that just walks and roars isn't scary. Merging all elements in a disturbing horrific whole is the key here, and also the AI behavior is part of that.

Enough fuzzy talk. In “Dumbass #2” I’ll explain a bit more about some technical AI aspects; State Machines. Now let's play chess and act smart.

Different than action games, but a very good AI showcase. By using "need meters", the AI would search and use objects to fulfill their highest priority needs... such as blocking the way for firemen.


  1. You've mentioned that you don't have much time to play lots of extra games before, I think, but I'd like to ask if you've heard of or played Miasmata. It's an open world game about exploring a deserted archipelago and making medicines from plant life, while avoiding a big cat that hunts you and toys around with you. The AI is something really special to experience and might serve as a little bit of inspiration for you!

    Also, are you planning on showing any monsters in future blog posts? I'm interested in reading this blog for development news and insight into game design, but I'm afraid that someday I'll have the enemies and such spoiled for me!!!

  2. Didn't hear of that game before no. But it looks seriously nice, I would believe it if they said it was made on CryEngine or something. Good to know such projects can be made by just two men. Not sure if I'll get a chance to pick it up some day, but I'll try to remember the name.

    As for showing monsters, I carefully decide what to show, and what not to prevent knowing half the game already when(if) it ever arrives. So that means you won't see a lot of monsters or special environments. Then again, you'll need them to advertise yourself of course. Without interesting shots, we won't be able to attract much needed artists either, and that means no-game in the end... Got to have some wildcards!