Last time
we talked about a Navigation Mesh; basically telling your A.I. where the
dancefloor is. Pathfinding algorithms and navigationmeshes are all tools to
help finding your way in a big bad game world. All in all, very common Game-Programming
stuff.
Less
common in the tutorial newspapers, is the decission-making part. We have a car,
we have asphalt, we have a navigator, but yet – destination unknown. Whether
its David Hasselhoff, KITT, or captain Picard, something has to drive that car.
This is where we enter the fuzzy parts of A.I. And also personal unknown
territory. I programmed a lot of machine regulators, graphics, and “axuiliary”
game-stuff (read engine architecture, loaders, physics, scripting systems,
navigation algorithms, and so on). But not so much of an actual game-logic
itself so far. Like building a new house, but never finished it till the point
we can do the interior and start living in it.
Game-logic
typically covers the rules of a game. What are the goals? When do you win, when
do you lose? And on a more detailed level, it covers puzzles, interaction,
scoreboards, inventories, pre-programmed scripts, player-controls/physics, and
also foe-controls; A.I. Varying from Pac-Man ghosts chasing you, to Carmageddon
race-cars trying to trash you. From Goomba’s walking from right-to-left, to
bionic supersoldiers trying to pin you down. Obviously, deciding where to go,
when to go, and how to get there, is a crucial part of A.I. And like I said, a rather
fuzzy one.
Predictable patterns
When
making a piece of machine-logic, the word “random” is forbidden. Depending on
the given parameters, the outcome of a subsystem should be 100% predictable. It
would suck pretty hard if your car randomly decides to start yes or no, when
turning the ignition key. When not doing so, there should be a damn good reason
for it, not just for the fun of it.
Well,
common sense, but game-A.I. breaks the rule here. If your opponent would always
react exactly the same, the game would become, well, very predictable. Not only
would it make the game too easy, it also makes your opponents appear very “synthetic”.
But hey, thank God we have a random() function! But - be careful! Too much
randomness will spoil your diner as well. You don’t wake up, put on a single green
sock, shit out the window, step naked in the car, drive backwards through the
garage-door, call your neighbor a lunatic, boil applejuice with fish, then get
back in bed again. Our human behavior is, more than you may like, pretty
predictable. I for instance always put on 2 socks, shit out the window, drive
naked to work in reverse, and drink my first coffee at nine A.M.. However,
there are subtle “random” differences in the execution. Sometimes I mix up
socks accidentally, and sometimes I drink my coffee at 9:05 instead.
You’ll
need some predictable (pre-programmed) patterns to make your NPC’s act human.
And some predictableness also helps making you feel good as a player, learning
the responses, flaws and weaknesses of your foes. Personally I’m not a fan of
MultiPlayer gaming, because the lack of that “Damn I’m good” feeling. I keep dying,
as some asshole caught me from behind, or randomly crossed paths and reacted
slightly faster. Just like the real deal… One moment you’re storming upon a
beachhead, next moment Heinz Panzerfaust floors you with a headshot. One moment
Nancy Sinatra sings your boots are made for walking, next moment you tumble in
a hole with Punji Sticks, pissed on by Ho Chi Minh. One moment you’re humming
in a Humvee, next moment an IED shreds it apart. Fun. Not.
When I
play a game, I generally don’t want a superrealistic experience, dying ingloriously.
I want to kick ass. Doesn’t mean the game should be easy, certainly not. But
dying should feel fair, not like random bad luck. And yeah, that sounds a bit
ridicously, as real-life war is verything but fair. But hey, we’re playing a
game. To have fun. Getting killed means I made a mistake; Lick my wounds,
learn, and try again. If your NPC logic is very unpredictable (read random),
you can’t really learn and act on it.
So, A.I.
needs to be fuzzy and unpredictable, but only to a certain extend (unless you’re
making bots for Battlefield1… anyone?! Please!). In programming terms, that
feels a bit unnatural. Always doing the same won’t work, completely random
picking doesn’t work either. What also feels unnatural is that your code has to
pretend “as if”. Game NPC’s don’t have real eyes or ears, and they can cheat
all the time. They always know exactly where the player is, they can aim their
guns 100% accurate, dodge lightning bolts, and respond within a millisecond. We
cover that up with some random inaccuracies and delay timers, but that has
little to do with how a brain really works.
No. Picture has nothing to do with this topic. Just some empty rooms, and I'm afraid they'll stay empty for a little while now that noone is working on graphics or texture/3D content at the moment.
Are we Human? Or are we Monsters?
Well, my
job last week(s) was to program some of those “Behavior Patterns”. Thanks to A*
and a navigationmesh, getting from A to B was relative easy. Deciding what “B”
would be on the other hand… I mean, where does a monster go? In a Soviet-like
skyscraper? To the bathroom? To the conference room? To his friends? And then
doing what?
Back in
the day, monsters just had to growl a bit and wait until the player showed up.
Then jump at him and probably getting shot while doing that. Not exactly a
brilliant role in the school’s play. But nowadays we want realism, meaning foes
have to make themselves useful in this virtual world. Whether sleeping, cooking
soup, repairing the generator or just being on the move – at least do something.
But obviously that’s pretty hard for a monster. They have to be scary, not driving
their cars to work, drink beer and watch football, or repair the generator.
Hell, some of my monsters don’t even have arms for that!
The good
news though, you will only see a little bit of that “Idle” behavior. More
likely you should avoid monsters, or end up either running or fighting with
them. Unless your monster carries an AK47 or plasma projectiles, the second
best choice is probably to just charge at you, meaning their destination location
will be you. So far, so good; Monster angry, monster runs at you, Benny-Hill
music, player flees, and then… Player out of sight. Now what?
Room service
Let’s say
the player ran a few rooms further, and hides under bed, as I would do. This is
a perfect scenario to show predictibility, artificial smartness, or straight
dumbness of your foes. For one thing, he could keep walking straight to the
player position. But that would be cheating of course. Slightly less cheating
would be to enter at least the bedroom, then act as if we’re sniffing and searching
the room. But if our monster would do that every time, it would be –exactly-
predictable.
Then
again picking a random target-point as soon as the player runs out of sight, would
be plain stupid. Chances that he’ll find you are nihil then, plus it doesn’t
feel like a logical response at all. In fact, I’ve been training my pet-Monster
in Tower22 a lot of times last two weeks, doing exactly this. I would run away
about 15 meters, hide under a table, then *hope* to see my monster-friend
searching nearby rooms. But of course he would take a wrong pick, and I had to
come from under the table, and start making noise and yell “Come here dumbass!
I’m here! Look!”.
I won’t
reveal the exact methods, as this pre-knowledge would ruin the fun of future
players, but let’s say our guy finally learned some better “Room-Sweeping”
methods. Picking the right directions (at the start of the search at least),
searching room by room, not using cheap cheats but “real” vision and acoustic
information. Only problem is… I trained my pet so many times now, that his
behavior is still preditable. To me at least. But that’s why they invented “Beta
Tasters”…
And if hiding doesn't work, I just finished some code to throw this waterkettle at somebody's head.
No comments:
Post a Comment