IA Logo


IA Information
Communication

Dave Mark's books

Post-Play'em - Observations on Game AI


Posts Tagged ‘line of sight’

First Encounter with F.E.A.R.

Monday, January 21st, 2008

Ok… this isn’t necessarily going to be a full-fledged review of all of the AI in F.E.A.R. (Monolith studios) Actually, to do that justice may take an entire book anyway. However, I have been playing it for a few days. One of the reasons that I had to get a hold of it anyway (I bought the Platinum Collection) is that I also got my hands on the SDK. It is a special treat to be able to see the actual code that went into making this ground-breaking gem of a game.

Anyway, I had a taste of the game a few months back via the downloadable demo from Gamespot. Even with that brief glimpse I was impressed. Now that I have been able to “dork with it” (research term) a little more, I have found myself saying a few things that surprise me.

“Son of a bitch! Where did he come from?”

This usually occurs when I fall into old patterns of thinking that the enemies are going to generally either stay put or move toward me in something resembling a direct assault. The first time this happened was on one of the more open, but box-laden arenas (which I am realizing was a design decision to show off this exact effect). I was slowly closing on a group of enemies… or at least where I thought they were (more on that later) when I get pegged from behind.

Now this isn’t a “Doom 3″ sort of assault (see my post on the subject) where the game either spawns a monster directly behind me or pops open a completely illogical hidden panel in order to literally kick me in the ass. As I thought about where this dude could have come from, I realized that it was one of the enemies that had been in front of me… but off to one side. He actually had circled around some obstacles and come up behind me. Sure, he probably didn’t realize that I had moved until he reached the spot where he had last seen me – but then rather than stand there, he continued on the only logical way I could have gone until he did discover me – and proceeded to politely pop a proverbial cap in my ass. Score one for the bad guys.

“Get your butt back here, wimp!”

Again, unlike shooters that I have played in the past, I encountered something that was actually almost frustrating in the novelty of it. It was realistic… which actually took some getting used to. When I would engage an enemy, they were just as likely to fall back as they were to move forward. I may take a shot or two at them only to see them walk, run, or dive around corners. They weren’t just going to cover, they were pulling back. This left me in the uncomfortable spot of having to move into a hostile environment where I knew dudes were camping for me… a position that I have always tried to put the enemy AI in. Now I know how effective it is – since I don’t really relish having to be the one doing the hunting.

“I don’t have all freakin’ day!”

Rather the opposite of above, I have tried to fall back to patterns of “agro-ing” the enemy and then dropping back to wait. As often as not, they don’t fall for it. If they know I’m there, they may very well not come for me – especially if I have nowhere to go. I’m used to being quite comfortable simply waiting around a corner with a shotgun to my shoulder ready to multi-perforate the first moving object that shows itself. I wait… and I wait… until I hear “Flush him out!” followed by that delightful ping of a grenade rattling around at my feet. Crap! But do they just come running dumbly around a corner like my cat hearing the food in his bowl? Nope… I gotta come to them.

“Would you show yourself, damnit?!?”

Somewhat related to the above is their stubborn insistence on using cover. Yeah, using cover is cool. We’ve been talking about it at GDC roundtables and message boards for years. For a while, AI programmers were all happy to use preset “cover points”. In a general sense, they looked good… but they were easy to exploit by just being in a place where that specific cover point was not truly a cover point at all. I get a feeling that these assholes would be perfectly comfortable playing hide-and-seek in a round room with a round pillar in the center of it. They seem to process cover the same way that a human does… “can this specific spot be seen by that dude over there?”

It gets really frustrating when I get into peek-a-boo mode with a guy. The enemy may position itself in the shadow zone of a strip of wall, a column or something to take cover. If I peek around one side, he will move a little to keep the cover between us. If I move to look around the other side, he moves also. There isn’t any invisible pre-defined spot that he’s on, he’s simply trying to not be seen. It pisses me off! Game AI is not supposed to act this way!!

“Quit acting like you guys like each other!”

[Cascade this from above...] If Ol’ Chuck there is running to cover like the little bitch that he is (my language gets salty when I’m pwning), do me a favor and let me gun him down like an arcade ducky. Do NOT annoy me with suppressing fire and all that military squad nonsense. He’s got his back turned and I want to blast him before he gets to that box because, once he gets there, we have already determined that he’s not going to show me anything more than the barrel of his gun for the next 20 minutes. You really are not helping me out by scattering an endless cornucopia of metal alloy in my general direction. It really is distracting and makes it awfully hard for me to jump out here in the middle of the doorway and calmly aim down the sight at his weenie little ass. You act as if he’s on the same team as you or something! What the hell is wrong with you, anyway? Sheesh!

“OK… that’s not funny anymore!”

This was my latest little adventure. I finally met up with one of these “Watchers”. They are like freakin’ Spiderman The Rabbit Puncher. The first time I saw one, I thought it was one of the hallucinations again so I didn’t think to actually shoot it until it walked up and bitch-slapped me… and then disappeared into the damn ceiling before I could blink. Uh. Ok… that was odd. Until, from the corner of my eye, I saw him (or his buddy) swing down from the ceiling, off the wall, over the desk, smack me on the butt again, and then perform a similarly frenetic egress.

For the next 3 minutes, I was twitching around all over the place like I was going through the DTs while on LSD. These two dudes were zipping up, down, “over, under, around and through” so as to keep striking me from behind. If I turned and saw them in time, they were just as likely to about face and retreat and replan. I began to realize that “replan” is exactly what they were doing. This wasn’t a pre-set script to whack me when I got to a certain location… they were making this up on the fly (crawl, leap, cling, whatever)! I finally managed to pop one with the shotgun but the other got me. I was too shaken by the fact that they were actually being clever that I had to quit… and start writing.

Damn.

I’m not sure what I want to do now. Crawl through a billion lines of AI code spread across 100 different AI classes so I know what they are doing… or keep playing so I can experience it more and maybe put myself into a position where I can actually understand some of the more esoteric stuff that I encounter in the code. Right now I’m too shaken up by my encounter with real AI to do either one.

Maybe I’ll go play Doom 3 instead. For some reason, creepy lighting and environments and stupid enemies is not as daunting as generically bland lighting and environments and monsters that actually act like they have a brain for a change.

Congrats to Jeff Orkin and company – I’ll see you next month at GDC. I will be honored and excited to meet you and “talk shop” such as it is. But don’t be surprised if I have a PTSD reaction and slug you before you get a chance flip over that damn table and hide behind it.

(More on F.E.A.R. AI at AIGameDev.com)

Call of Duty 2: "I saw that grenade coming!"

Friday, November 30th, 2007

Another quick observation from my perusal of “Call of Duty 2″ for Xbox 360. I’ve noticed rather often that, when I toss a grenade, the intended “recipients” seem to know that it is coming as soon as it leaves my hand. They will yell some German variant of “Holy crap, there is a grenade! Run, dude!” This is all well and good if they are seeing the grenade coming and would like to amscray prior to its arrival. However, the quirky behavior comes in when I am doing something like bouncing it off a wall around a corner. I will hear them shout prior to the offending pineapple even making it to the corner that I am trying to circumnavigate. In other words, they either saw the grenade through the wall, or there is some sort of mirror-like sheen on the wall that allows them to see it coming.

The programmers seem to be using a messaging architecture wherein an event triggers a reaction in all agents within range. For example, if the grenade were to explode in front of them, the explosion itself would send a message out to nearby agents saying “if in range, die violently”. Messaging architectures are opposed to polling architectures where the agent is constantly looking through his environment to see if there is something to react to. Using the same example, the agent would constantly have to scan the nearby world to see if a grenade has exploded. Since grenade explosions are relatively rare, this would be a lot of wasted CPU. As you can see, messaging architectures are more efficient for event based situations.

In this case, the landing area of the grenade is roughly calculated. If the projected landing spot is near an agent, they react appropriately. They yell out warnings and move away if necessary.

However, the programmers would have faced a quandary as to when the grenade itself should send a message. If you wait until it lands or bounces off of something, it would discount the very possible scenario that they could have seen it flying through the air in the first place. If it is triggered when it is thrown, it creates the issue I observed above – that they know it is there despite the fact that they should not be able to see it at all.

One solution (albeit not a very efficient one) would be line of sight checks along the path of the grenade. Once a grenade launch has happened – and a message dispatched to the agent – the agent would now have to do a line of sight (LOS) check. If the grenade is visible, all is well – react appropriately. If it is not visible, the agent would have to change techniques to a polling architecture specifically doing periodic LOS checks at the grenade. When you consider that there may be 10 or 20 agents (friend and foe) in the area, multiple grenades in the area, and each agent-grenade LOS check would need to be done many times per second, the computational overhead adds up very quickly.

Another potential workaround would be to create a plane that is the intersection point of the path of the grenade and the visible area of the agent. At that point, the “see grenade” event can be triggered once the grenade passes that point. That seems to be not much of an improvement since there would be as many planes as there are agents and the grenade would now have to poll the planes many times per second. The overhead would be similar to the first example.

There is another way of handling that, however. Once the plane is generated, the distance from the source to the intersection of the plane can be calculated. Since the velocity of the grenade is near constant, the time delay until the projectile reaches the plane can be established. The message can be sent with a delay of x number of frames (or any other way that the game loop timer is built) so that the message is delivered and activated at the point that the grenade would have come into sight. No polling is necessary at this point. Just like before, a single event message is sent. The only additional overhead would be creating the planes representing the lines of sight for the agents in the area. In fact, if the LOS check is successful at the beginning of the throw, the plane creation is not even necessary. If an agent is going to yell to his squadmates about the throw, you don’t need to do LOS checks for them at all – they already know. It would take some testing to find out how much overhead this eats up, but the result would be that you could do stealth/surprise grenades in a much more realistic fashion rather than the current “I saw it coming around the corner” effect.

(More observations of “Call of Duty 2″ for Xbox 360)

Add to Google Reader or Homepage




Content 2002-2015 by Intrinsic Algorithm L.L.C.

OGDA