SakeTami
comfortjones
comfortjones

patreon


Recent AI Thoughts and Accomplishments

In August I wrote an article here about how I had recently given far more control of AI behavior to level designers. While this did allow me to fine tune fights, it incentivized me account for lots of potentially bad outcomes in subpar levels with mark up rather than creating levels that help the AI look their best. Combat was starting to feel "fragile" with soldiers looking dumb when they weren't given enough mark up to work with in the level, so I decided I need to take a final stab at finalizing my AI and polishing the game. My two main goals: Expand my AI's ability to make good decisions while addressing problematic arenas with better layouts that naturally encourage more fun gameplay. In this article I'll be addressing the first goal, in about a week I should be covering the 2nd.


Bad positioning from Combine soldiers was the main motivator I had for initially trying to add a lot more level designer control over npc behavior. Soldiers would sometimes flank past you even in very linear spaces with no good route to do so, or avoid pushing up as quickly as I wanted in dramatic fights. Mark up seemed like a good way to get a hold of this and to an extent it can be in a linear shooter, but I found myself constantly fiddling with all kinds of variables to make sure soldiers were only in "fun" places to fight.  I needed a way to get soldiers to prefer certain situations consistently without a level designer's input. The solution came by expanding how NPCs can look for cover and shoot positions.


By default in Half-Life 2, when NPCs look for a place to attack from or a place to hide, they look for a movement node that meets their conditions. So for a cover position they check if their enemy can see them there, and then whatever other small considerations they might have. If the cover checks out, they'd pick it right away. This "pick the very first valid choice" approach consistently got in my way in the past when trying to make soldiers position a little more intelligently. There was no way to nudge a soldier to pick one spot over another, it was basically all or nothing. For instance, I wanted them to avoid being too close to each other, but simply not allowing them to be too close to other squadmates completely broke their ability to fight in plenty of situations, especially in smaller arenas. To address this, I rewrote their node finding behavior to allow them to continue looking for an ideal node position.


So as an NPC looks for cover, it does a score check on any valid node. So a soldier will check if there's squadmates near the node (they want to avoid bunching up), if they can easily attack from the node, if the node isn't too close to their enemy, etc., and then adds up a score based on these conditions. If the current node returns a new high score, they store that and continue searching til they've hit a set distance. This lets me have NPCs prefer certain positions without having to arbitrarily restrict them. So instead of needing mark up to mandate what a soldier can do, I can rest easy knowing what his preferences are, and map around those. If soldiers are consistently doing something I don't want, I can bias their preferences away from those kinds of situations. Best of both worlds!


Another advantage to this system is the fact that as they search, they can store a path distance with each node. By default in HL2, NPCs would simply do a simple ray cast from one point to another to determine distance which resulted in certain positions which in reality were quite far away being considered fairly close. With this little path distance check, I've got another way to limit bad behavior, such as taking a crazy long path to get to cover that's on the other side of a wall because it's technically close by.


None of these changes get NPCs acting dramatically smarter in areas where they already played well, but it has lessened a lot of problematic behavior that was making creating a good arena kind of a pain. This is honestly the cruel reality of AI work, players notice nice animations and barks that give  the NPC the illusion of intelligence, not the actual decision making the AI is or isn't making. The real hard work basically goes into making enemies look less stupid, which isn't something that's really noticed in gameplay. Pretty rare for a playtester to say "wow they didn't do stupid things!" but it's still worth doing. 


Next up, I'll be going over one of the problematic arenas that has benefited from a combination of these AI changes and some level tweaks to better encourage fun gameplay. For the sake of clarity, I've removed the original article referenced at the start as I want at least some of these to be a useful information source for people and if I no longer stand by something, I'd rather it not be cluttering things up. Thanks for reading, and be sure to yell at me if I'm super late on getting the follow up done for this!



More Creators