Underhell is a Source Engine game developed by the Underhell Team in collaboration with We Create Stuff. Underhell Chapter 1 requires ONLY Source SDK Base 2007 installed. No Source game is required.

Report RSS Enemy AI Improvements & Sneaky Gameplay

This is a short explanation of how the "Sneaky Gameplay" works in Underhell, and how the enemy AI was improved and tailored to help it work correctly, followed by a short tutorial on the Level Design.

Posted by on - Basic Mapping/Technical

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.

  1. Enemy Soldiers see you instantly, given their 180° + field of view.
  2. The "Combine" voices are hard to understand, therefore all the player hears is jiberrish
  3. 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...


(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.



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.



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

SetSquadTemp (0-1)


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"

// 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.


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:

uh_SpotBodies (0-1)

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)


The sneaky levels have a "Backup System", that dynamically sends an additional squad in the map, randomly equipped with a Riot Shield or a Ballistic shield.

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.

Programming by Carlos "Charly" Sotelo

Underhell, new and improved edition.

This time it will become an even bigger hit;

Gaben will play it!

Reply Good karma Bad karma+16 votes

He definately (probably) think that Underhell is worth the weight!

Reply Good karma Bad karma+7 votes

Based upon my playthrough of the prologue and the description you are giving of the new AI, Underhell will go from being one of the most fun mods ever, to an absolute do-not-miss for any shooter/horror/stealth/puzzle fans . Simply put, thank you!:D

Reply Good karma Bad karma+10 votes

This seems to be a lot more interesting than before.

Reply Good karma Bad karma+6 votes

"That said, unlike some other games, the reinforcements are NEVER unlimited."

Thank you for this. Unlimited enemy reinforcement always really annoyed me.

I'm interested to see the randomised patrols; without seeing it in action it seems as if it could possibly end up being a bit weird or unrealistic (e.g. a soldier walking the same path and back twice, when he has another area to guard as well).

Conversations, on the other hand, sound awesome already.

Temporary squads seem pretty useful, but what happens if you have 3 of the 4 NPCs in a normal squad gain LoS on an ally from a different squad? Those three will become part of the Temp Squad but the fourth NPC is now no longer receiving any target info until its squadmates stop being part of the Temp Squad.

Or have you made a way of allowing the Temp Squad info sharing to coexist simultaneously with normal info sharing via squads?

Reply Good karma Bad karma+2 votes
Mxthe Author

The tempsquad co-exists with the already existing squads.
It's just a new type of squad, which is temporary, and based on LOS.

Reply Good karma+3 votes

Really love the sentences script, It's a shame not many people utilize it for their own mods. It's only a couple hours of work to get done if you know what to do.

Reply Good karma Bad karma+1 vote

You didn't understand what the Combine said!? Now I'm proud, because I totally did ^^ But they had a couple of weird codes like "ripcord", "biotics", "necrotics" and others that one kinda had to guess/learn? Didn't take long though :P

Reply Good karma Bad karma+1 vote

That's some very pro work right there, I'll really look forward to seeing it in game =)

Reply Good karma Bad karma+2 votes

I will be making an unofficial expanshun for this mod called Overhell

Reply Good karma Bad karma+1 vote

Is it possible to make like your enemy's think that they can't beat you so they run to there friends

Reply Good karma Bad karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Follow Report Profile
Half-Life 2
Send Message
Release date
Mod watch
Related Mods
Related Games
Half-Life 2
Half-Life 2 First Person Shooter