Tactical AI Kit: Reacting to Threats
by Bryce · 10/15/2008 (9:25 pm) · 23 comments
Hello Community!
I have finally accomplished something that was much needed for the Tactical AI Kit--reacting to threats. So far, it's pretty basic, but I'm quite glad that I implemented in two hours what many games today don't offer with AI.
After a while, I grew tired of having my AI Players getting stupidly killed because they weren't facing the right way and couldn't figure out that he was being shot at. My original idea was to make the AI Players cheat; when they come under fire, they know where the threat came from and will immediately react.
Problem: I HATE cheating AI. Nothing bothers me more that being unable to have fun sniping in a game because you instantly come under fire from enemies who shouldn't know you exist. I was playing co-op Chaos Theory at a friend's house not too long ago, and was sniping an enemy from across a system of docks who was blazing away at my friend. I hit him in the leg from 100 meters or so, with a silenced weapon, and I suddenly came under fire. There is no way he heard that shot across the docks while his assault rifle was going off. That made me mad, not just because I was promptly killed, but because a game that relatively new needed to resort to cheating AI.
So, I looked for a solution that would allow AI Players to move intelligently (while also looking like they are panicking) when they come under fire while not engaging an enemy. At that same friend's house, I was playing the first Ghost Recon game and noticed something interesting. At the bottom of the screen, there is a little compass-thingy that looks like this:

Whenever the player comes under fire and is close enough to hear the shot, the section that points closest to the location of the gunshot turns red. This gave me an idea. Every 25 milliseconds, the AI Player performs a quick radius search and sees if there are any enemy players firing their weapon (okay, okay, some cheating is employed here to get the firer's team, but without it, they would mistake friendly players firing as possible enemies, which looks pretty bad). This is not as performance-costly as it sounds. Now we check the distance of the shot and the datablock of the weapon that was fired. In the weapon datablock, a field needs to be added that specifies how close an AI Player has to be to hear it firing (rifles could have a sound radius of around 400, lower distances around 40 or so could be used for silenced weapons, etc). If a gunshot is heard, the location of the shot is altered from 0 to 90 degrees based on the distance of the shot, so that there is some guess error.
If at any time we notice a projectile sail by us or a bullet hit somewhere close to us, we enter the REACT state. The NPC checks if we have heard any gunshots, and if we have, we move to cover from that position while watching it (he has a look around behind him every once in a while, too), while occasionaly wandering back into the open cautiously to find the shooter. If the NPC hasn't heard any enemy gunfire, he basically runs around while constantly searching in every direction (panic). So far, this is working extremely well. There aren't many things more fun than watching these little guys scramble like ants and run for cover through a rifle scope.
Rate and comment!
I have finally accomplished something that was much needed for the Tactical AI Kit--reacting to threats. So far, it's pretty basic, but I'm quite glad that I implemented in two hours what many games today don't offer with AI.
After a while, I grew tired of having my AI Players getting stupidly killed because they weren't facing the right way and couldn't figure out that he was being shot at. My original idea was to make the AI Players cheat; when they come under fire, they know where the threat came from and will immediately react.
Problem: I HATE cheating AI. Nothing bothers me more that being unable to have fun sniping in a game because you instantly come under fire from enemies who shouldn't know you exist. I was playing co-op Chaos Theory at a friend's house not too long ago, and was sniping an enemy from across a system of docks who was blazing away at my friend. I hit him in the leg from 100 meters or so, with a silenced weapon, and I suddenly came under fire. There is no way he heard that shot across the docks while his assault rifle was going off. That made me mad, not just because I was promptly killed, but because a game that relatively new needed to resort to cheating AI.
So, I looked for a solution that would allow AI Players to move intelligently (while also looking like they are panicking) when they come under fire while not engaging an enemy. At that same friend's house, I was playing the first Ghost Recon game and noticed something interesting. At the bottom of the screen, there is a little compass-thingy that looks like this:

Whenever the player comes under fire and is close enough to hear the shot, the section that points closest to the location of the gunshot turns red. This gave me an idea. Every 25 milliseconds, the AI Player performs a quick radius search and sees if there are any enemy players firing their weapon (okay, okay, some cheating is employed here to get the firer's team, but without it, they would mistake friendly players firing as possible enemies, which looks pretty bad). This is not as performance-costly as it sounds. Now we check the distance of the shot and the datablock of the weapon that was fired. In the weapon datablock, a field needs to be added that specifies how close an AI Player has to be to hear it firing (rifles could have a sound radius of around 400, lower distances around 40 or so could be used for silenced weapons, etc). If a gunshot is heard, the location of the shot is altered from 0 to 90 degrees based on the distance of the shot, so that there is some guess error.
If at any time we notice a projectile sail by us or a bullet hit somewhere close to us, we enter the REACT state. The NPC checks if we have heard any gunshots, and if we have, we move to cover from that position while watching it (he has a look around behind him every once in a while, too), while occasionaly wandering back into the open cautiously to find the shooter. If the NPC hasn't heard any enemy gunfire, he basically runs around while constantly searching in every direction (panic). So far, this is working extremely well. There aren't many things more fun than watching these little guys scramble like ants and run for cover through a rifle scope.
Rate and comment!
#22
10/18/2008 (12:58 am)
Okay, that's an interesting way to do it. I'm thinking of implementing some basic flocking for squads, directly in AIPlayer's movement code. I don't know whether it would be too costly for my purposes; the calculations aren't that expensive...
#23
10/18/2008 (11:57 am)
At the moment, they all just move towards the squad leader, but eventually I will add leader position offsets for each squad member so they can assume some kind of wedge formation when idle, or a single-file line when moving. 
Torque Owner Bryce
Tactical AI Kit
edit: clarity