{"id":4093,"date":"2009-08-13T09:33:09","date_gmt":"2009-08-13T13:33:09","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=4093"},"modified":"2009-08-20T09:46:41","modified_gmt":"2009-08-20T13:46:41","slug":"ai-follies-detection","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=4093","title":{"rendered":"AI Follies: Detection"},"content":{"rendered":"<p>Inasmuch as the bad guys are a part of the program you&#8217;re running, the bad guys always know where you are.  The game knows where you are in the same way that a puppeteer knows where the puppet is.  Your position in the game is just another variable it&#8217;s constantly tracking as part of running the show.  <\/p>\n<p>But unless you want every bad guy to begin homing in on the player the moment the loading screen vanishes, you need to pretend you don&#8217;t know where they are.  Detection is the system of deciding when to stop pretending you can&#8217;t see them.  By default the bad guys can draw a bead on the player and ding them between the eyes at an unlimited distance the instant a clear shot becomes available.   AI is used here not to make the foes more potent in combat, but to make them <em>less<\/em> so.  <\/p>\n<p>This usually begins with line-of-sight checking.  Calculate a line from the AI in question to the player.  If that line hits (intersects) anything before it gets there, then something is in the way and obstructing the AI&#8217;s view of the player.  A LOS check used to be kind of a big deal, but these days they&#8217;re generally considered to be an inexpensive operation.  Still, there <em>is<\/em> a cost to doing the check and thus an upper limit on how many you&#8217;ll want to do a second.  <\/p>\n<p>Sounds easy, right?<\/p>\n<p>That&#8217;s the state of detection as it existed around Wolfenstein, but once you&#8217;re dealing with complex 3D environments with varying light levels and trying to make believable enemies things get really hairy. The goal of your AI is to not make a fool of itself by being too perceptive or not perceptive enough.  Nothing will distance a player from the game and break immersion like having a bad guy perfectly <a href=\"?p=1470\">track them while they are completely hidden behind cover<\/a>, or see them a half mile away.  In the <a href=\"?p=4085\">initial post<\/a> in this series I mentioned AI bad guys that had &#8220;super-senses&#8221;. Counter-intuitively, super senses are the result of exceedingly <em>stupid<\/em> AI.  In effect, <em>it&#8217;s too dumb to know it shouldn&#8217;t be aware of you yet.<\/em><\/p>\n<p><strong>Complex occlusion<\/strong>:  <\/p>\n<blockquote><p>That LOS calculation we talked about a second ago is fine for simple scenarios, but it falls apart quickly in anything less than a barren cube-shaped room.  What part of the player is the bad guy trying to look at?  Sure, you project the line <em>from<\/em> the bad guy&#8217;s eyes, but where does it go <em>to<\/em>?  The player&#8217;s eyes?  If so, then you end up with the hilarious &#8220;I can&#8217;t see you so you can&#8217;t see me&#8221; logic.  If you&#8217;re standing in the open but you have something hiding your eyes, then you&#8217;ll be invisible to the bad guys.  Picture Chris Farley hiding behind a lamp.  <\/p>\n<p>So, the AI needs to do several LOS checks to various parts of your body.  It needs to be able to see the top of your head poking up from behind the couch, your legs sticking out from behind saloon doors, and your shoulder poking out from around a corner.<\/p><\/blockquote>\n<p><strong>Field of View<\/strong>  <\/p>\n<blockquote><p>Obviously AI should not have eyes in the back of their head, and there needs to be some limit on how far they&#8217;re allowed to see.  Generally, you see quite far and in great detail directly ahead of you, but this high level of perception falls off quickly at the corners of your vision.  (The edges of our vision see mostly motion and colors and changes in brightness, and aren&#8217;t very good at picking out shapes.)  People are also generally very bad at looking up or down, and their vertical vision can often be even worse than their peripheral vision.<\/p>\n<p>Now, most people intuit all of this, even if they don&#8217;t <em>know<\/em> it.  We usually have a sense of when other people should be able to see us, and deviations from these expectations are jarring. AI that can detect an unmoving player out of the corner of his eye at fifty meters feels like a rotten cheater.  An AI that only sees a 90 degree cone in front of him feels like a bumbling moron.  (Although the latter is often forgiven for the sake of being sporting.  Because they&#8217;re viewing the world through a monitor, the player can only see a ninety degree cone themselves.)<\/p><\/blockquote>\n<p><strong>Light Changes<\/strong><\/p>\n<blockquote><p>This has become more important since the introduction of HDR lighting in games.  It&#8217;s now possible for the player to be blinded to areas with vastly different light levels. If you&#8217;re standing in the sun, you can&#8217;t see into the dark train tunnels.  If you move to the tunnels, the area outside becomes too bright to make out.  Players expect these restrictions to apply to AI.  <\/p>\n<p>But this one can get really tricky, and I don&#8217;t think a game has done it right yet.  I first raan into the problem in Thief, when I&#8217;d crouch in a doorway.  I&#8217;d be in darkness, but the room behind me would be well-lit.  The guard in front of me should have spotted me instantly.  In real life, it would be safer to stand in the lit room than to stand in the dark with the light directly behind me, forming a perfect back-lit silhouette.  Eventually players learned to rely on the visibility gem instead of their common sense to judge how visible they were.  <\/p>\n<p>I suppose it would be sensible to extend any LOS check that succeeds.  That is, if we draw a line from the bad guy&#8217;s eyes to (say) the player&#8217;s shoulder and it actually hits, we then continue to follow the line until it hits <em>something<\/em>.  We can then compare the light level of the player to the light level of the thing stuck, and have any variance in those values count against the stealth rating of the player. This sounds reasonable, but I suspect that we&#8217;d see the failure modes move to somewhere else if we did this.  Definitely one that requires more thought.<\/p><\/blockquote>\n<p><strong>Camouflage<\/strong><\/p>\n<blockquote><p>Just because the LOS check passes doesn&#8217;t mean the AI should truly &#8220;see&#8221; the player.  If I&#8217;m wearing camo and crouching in the underbrush, it feels very unfair to be spotted by the AI.  However, if I&#8217;m just behind some furniture it feels perfectly reasonable to be spotted.  <\/p>\n<p>So the LOS check needs to do more than just figure out if I&#8217;m visible.  It needs to examine what sort of things are obscuring me, how much of me is visible, how much I should blend with those things, and if I&#8217;m moving.  This is complex <em>and<\/em> it requires that your artists get involved with the AI system by tagging objects according to how camo-friendly they are.  A fern? Very camouflaging.  A beach umbrella?  Not so much.  I&#8217;ve never run into a game where I thought this was done well.  In Crysis, the enemies sometimes had foliage-penetrating X-ray vision, and being spotted while sitting still in a thicket is no fun. <\/p><\/blockquote>\n<p><strong>Subjective Perception<\/strong><\/p>\n<blockquote><p>This is the most complex one, and the most annoying to players.  Generally soldiers don&#8217;t immediately begin shooting to kill the moment they see someone milling about in the distance.  There is nothing more tedious than the army of clairvoyant  soldiers who can tell friend from foe at two hundred meters with enough certainty that they are willing to shoot to kill.<\/p>\n<p>However, if I&#8217;ve already gunned down half the guys in their base then I <em>do<\/em> expect this level of paranoia from the AI.  Uh, unless there is no way for this particular bad guy to have heard about the attack, in which case he should go back to be more curious than trigger happy.  Unless he&#8217;s heard shooting.  Or he&#8217;s spotted me in a forbidden area where only an enemy would go.  (I think it&#8217;s fair to assume that anyone coming out of the sewers or air ducts is a troublemaker. (Unless there are civilians around.))  <\/p><\/blockquote>\n<p><em>Aren&#8217;t you done with the AI yet?  We&#8217;re going gold in a few weeks.<\/em>  <\/p>\n<p>Having these systems fail is often worse than not having them.<\/p>\n<p>In one of the Cat in the Hat books, the story features a red mess that the kids keep trying to clean up.  Each attempt to do so just ends up moving the mess from one place to another.  I&#8217;m sure this was an environmental message of some sort, but it&#8217;s a nice metaphor for the problems that AI programmers are up against.  Every time you try to fix a hole in the AI you just move the failure mode to a new situation.  Adding better complex occlusion just makes the field of view problems stand out.  Fixing those reveals the problems with camo.  Fixing that (if you can) will expose the shortcomings in subjective perception.  And so on.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Inasmuch as the bad guys are a part of the program you&#8217;re running, the bad guys always know where you are. The game knows where you are in the same way that a puppeteer knows where the puppet is. Your position in the game is just another variable it&#8217;s constantly tracking as part of running [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[],"class_list":["post-4093","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/4093","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4093"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/4093\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}