Say what you want, HL2 has one of the best Artificial Intelligence I have seen in a game.
Soldiers work together, communicate, flank the player, flushes him with grenades, and will patrol around the last area where the player was seen if he disappears.
This is all HL2's Default AI, but a few factors can make it seem less impressive than it actually is.
- Enemy Soldiers see you instantly, given their 180° + field of view.
- The "Combine" voices are hard to understand, therefore all the player hears is jiberrish
- The way the AI patrols by default looks pretty dumb, unless given specific context.
Very early in the development of Underhell I knew I wanted to have a sneaky/tactical gameplay possibilities, therefore I had made a list of features that I wanted to see in, but at the time I designed these Levels, I did not have the code or those features yet, so I had to keep everything in mind before actually being able to test it.
That said, it worked out pretty well...
FIELD OF SIGHT
(or field of view)
The default field of view of the "npc_combine_s" is based around a real Human's being field of view, which is slightly above 180°. This makes it nearly impossible to sneak around them unless they are turned away.
So our first step was to create a set of keyvalues and input to determine the FOS and the View Distance.
Keyvalues: uh_fos uh_viewdistance
Those 2 keyvalues are added in the NPC's properties in hammer, by turning SmartEdit off, they allow for very precise setting of the field of view and the view distance.
We also implemented a set of inputs allowing us to change these values in real time.
Inputs: setfos setviewdistance
As soon as we had these settings in the game, we realized just how cool it was to be able to sneak around a soldier without being detected.
As for the "realism" in lowering the Field Of View, the levels in which it is reduced are extremely dark, and the soldiers are wearing gas masks.
In Source engine, only NPCs that are in the same "Squad" will work together and communicate.
The trick is, that even if one soldier of the squad is at one side of the map, and another at the other end of the map, they will still "Work Together" and be alerted together when one of them spots the player.
So I knew I would need multiple Squads, but the problem in splitting up the squad is given when, 2 squads actually meet in the map, and do not even communicate or work together to take down their enemies.
So we came up with a Temp Squad system, when 2 NPCs that are allied to each other, are within each other's line of sight, they are placed in a "Temporary Squad" and begin sharing target information, independently of their squadname.
Whenever the line of sight is lost, the "Temp Squad" is broken, and they cease to communicate, UNLESS they are within the same Squadname.
This makes it so that every soldier in the game work together when they are close to each other, independent of which squads they are in.
But this system does is not specific to soldiers, but to every NPC type in the game, as long as they are allies, they will now work together.
The following keyvalue must be set to the NPC's properties by turning SmartEdit off :
SquadTemp : 1
You can also dynamically turn the SquadTemp on and off with the following inputs
Another major detail in a believable behavior, is the Voices of the soldiers, and how they communicate.
Half Life 2 has 27 "SENTENCES" categories for Soldier Communications.
These can be found in "Scripts/sentences.txt"
//PAIN //DIE // I am about to start shooting // My enemy is close and I can see him // I am moving in // I am still alert and pursuing enemy // Nobody has seen enemy in 10 seconds // Nobody has seen enemy in 5 seconds // I just saw a friendly die // Just found enemy after lost long // I am throwing a grenade // Enemy Grenade lands nearby (one man only) // Something dangerous nearby, need to run // Player Alert - first contact and I'm the squad leader // Last soldier's hit damaged player significantly // Monster Alert - first contact and I'm the squad leader // Monster Alert - by type // I killed a monster // I was hit and it hurt. I'm taking cover // I took damage but it didn't hurt much // I'm the last guy in the squad // Player is dead // Idle statement - my status, no enemy // I'm asking a question while idle, which may be answered with affirmative // Answering affirmative // Answering all clear // Questioning if all clear
So I was looking for a voice actor with a very good "Military" voice and way of speaking, and I stumbled across Michael Tsarouhas.
In a few days he has sent me over 400 lines for the first 7 categories, which are the most commonly spoken, and I have to say I was sold.
We have over 32 lines per category, said in many different ways, and honestly this simple addition provides an incredible amount of "immersion" to the game.
I have spent countless hours just observing Soldiers behave in squad while fighting other enemies, and I have to say I am impressed by the depth of the HL2's default AI, in ways I wasn't before, simply because I couldn't understand a damn thing the "Combine Soldiers" say in HL2.
DYNAMIC PATROLS & CHATTER
Soldiers in HL2 have no "default patrolling" system, they have a simple input called "StartPatrolling", which makes them walk around in circles, but they do not navigate a level by themselves unless told to.
I knew that I wanted dynamic and randomized patrols in the Sneaky Levels, because I wanted people to be able to play them over and over again without it being exactly the same twice.
So I came up with a system that randomly teleports a "target" at predefined locations around the level, and the soldier will dynamically create his path to the target, depending on his current position.
Based on a randomized timer, the soldier's target will teleport somewhere else, and the soldier will therefore update his navigation path to get to the target's new position.
This makes extremely dynamic and realistic patrolling system, that is rather hard to predict, but since the locations at which the target teleports are preset, it is not impossible to understand the "patrol area" of a specific soldier.
In addition to this system, I have created another dynamic "Conversation" system based on whether 2 soldiers on patrol find themselves in the same location.
In which case they both stop patrolling, have a randomized conversation, and then resume their patrols.
These Conversations can give very important information to the player about what is going on in the location the player is currently in.
As previously mentioned in the "Bodygroups, Gibs, Ragdolls and Decals" tutorial, we have created a system which allows for soldiers to "Detect" dead bodies.The Keyvalue to add to an NPC to make them find bodies is the following:
An input can also be called to toggle this function On and Off
When the SpotBodies is on, the NPC will fire the following outputs when they spot a body:
OnSpotSoldierBody : Fires when a Soldier body was found
OnSpotI******dBody : Fired when a SPOILERS body was found
OnSpotDefaultBody : Fired when any other type of npc ragdoll was found
In this output link "!caller" is the body itself, and "!activator" is the NPC who spotted the body.
Here's a way it can be used :
OnSpotSoldierBody !Activator WalkToEntity !caller
This output will make the person who found the body (!activator) Walk to the dead body (!caller)
Depending on how often the player is spotted, and whether or not he opens fire, Soldiers in the map will call for backup, and soon after the nearest Core Access will open, letting in the reinforcements.
This can make the gunfights very dynamic, if the player decides to go in Guns Blazing.
I do not recommend one approach or the other, I will simply say that the game has been designed to support as many approaches as possible, while giving possibilities to the player to change tactic at any given time.
That said, unlike some other games, the reinforcements are NEVER unlimited.