Tactical AI Kit: Pursuit, Close Combat, and Sniping
by Bryce · 05/17/2009 (12:03 pm) · 10 comments
Hello children!

Woot, more features. Read on or fail.
What to do when there's no cover
My AI system functions well in a close-quarters environment, or anywhere with lots of objects to take cover and navigate through. A new map I played with showed me that they don't perform well when there is no cover around. They stop where they are and they will shoot at you on sight.
There was a problem with that. They only shot *on sight*. Meaning, if an enemy is at a far enough distance to the point which they cannot be seen unless moving or firing, we'll see some pretty wacky behavior. If the NPC sees the player running across a field far away, for example, the NPC will stop, crouch, and squeeze off some rounds if there is no cover to do this from. If the player stops moving, they are no longer visible, and the NPC sits there.
My next plan was to add a wander function during their attack procedure. This resulted in the NPC running away aimlessly and shooting insanely in the player's general direction. Hmmm, no. Not quite what I'm looking for.
Yesterday I added a close attack state to the AI code, which defines separate behavior for NPCs who have no nearby cover or who decide that cover is not worth running to. This state is pretty simple now, but will be enhanced as much as I see fit.
There was an article about the Killzone AI that inspired me to work on this state. The close attack state looks at path nodes within a certain radius of the NPC, and then assigns a cost to each one based on preferred attack range, line of sight, and other factors, to see which node is best to attack from. The NPC moves to that node and fires at the enemy.
I incorporated a system like this for the close attack state which does the same thing with the path nodes. When the NPC can't find cover, he should be able to find a location as advantageous as possible to avoid being killed.
The enemy's running away! What ever shall I do?
Chase after him, maybe?
Close attack worked great, until I run and hide. My new test map contains tons of hills and trees to dart around, making it easy to hide in the woods. Wouldn't it be great if the NPC would follow me into the woods to kill me? Yes.
Whenever the NPC sights an enemy, he remembers where he is. That way, once the enemy is out of sight, he can move to the last known position. From there, if he sees the enemy again, he will start attacking again. If we don't see him from there, we can initiate a search from that position. Some pretty epic chases have resulted from this :D
Do I really need to empty my clip on this guy?
Inspired by the attack code in Killer Kork, the close attack state now has support for sniping. If a target is moving slowly enough, is far enough away, and it does not appear to know of the NPC's presence, the NPC will snipe. The view distance will be increased (field-of-view is also decreased), the think rate will be tripled, accuracy will be improved, and the NPC will aim for the target's head.
This is a quick video of the new close attack procedure. I run around a few of my maps with the player set to not receive damage.

Woot, more features. Read on or fail.
What to do when there's no cover
My AI system functions well in a close-quarters environment, or anywhere with lots of objects to take cover and navigate through. A new map I played with showed me that they don't perform well when there is no cover around. They stop where they are and they will shoot at you on sight.
There was a problem with that. They only shot *on sight*. Meaning, if an enemy is at a far enough distance to the point which they cannot be seen unless moving or firing, we'll see some pretty wacky behavior. If the NPC sees the player running across a field far away, for example, the NPC will stop, crouch, and squeeze off some rounds if there is no cover to do this from. If the player stops moving, they are no longer visible, and the NPC sits there.
My next plan was to add a wander function during their attack procedure. This resulted in the NPC running away aimlessly and shooting insanely in the player's general direction. Hmmm, no. Not quite what I'm looking for.
Yesterday I added a close attack state to the AI code, which defines separate behavior for NPCs who have no nearby cover or who decide that cover is not worth running to. This state is pretty simple now, but will be enhanced as much as I see fit.
There was an article about the Killzone AI that inspired me to work on this state. The close attack state looks at path nodes within a certain radius of the NPC, and then assigns a cost to each one based on preferred attack range, line of sight, and other factors, to see which node is best to attack from. The NPC moves to that node and fires at the enemy.
I incorporated a system like this for the close attack state which does the same thing with the path nodes. When the NPC can't find cover, he should be able to find a location as advantageous as possible to avoid being killed.
The enemy's running away! What ever shall I do?
Chase after him, maybe?
Close attack worked great, until I run and hide. My new test map contains tons of hills and trees to dart around, making it easy to hide in the woods. Wouldn't it be great if the NPC would follow me into the woods to kill me? Yes.
Whenever the NPC sights an enemy, he remembers where he is. That way, once the enemy is out of sight, he can move to the last known position. From there, if he sees the enemy again, he will start attacking again. If we don't see him from there, we can initiate a search from that position. Some pretty epic chases have resulted from this :D
Do I really need to empty my clip on this guy?
Inspired by the attack code in Killer Kork, the close attack state now has support for sniping. If a target is moving slowly enough, is far enough away, and it does not appear to know of the NPC's presence, the NPC will snipe. The view distance will be increased (field-of-view is also decreased), the think rate will be tripled, accuracy will be improved, and the NPC will aim for the target's head.
This is a quick video of the new close attack procedure. I run around a few of my maps with the player set to not receive damage.
#2
05/17/2009 (9:36 pm)
Wow, very nice, ill want see your kit with the combat starter kit... :D
#3
Cant wait to see what you have next!
05/18/2009 (4:57 am)
That looks great! AI chasing me makes it a bit more challenging to get safe.Cant wait to see what you have next!
#4
Watching these blogs is great inspiration... I'm itching to get into some AI work of my own. But I'm not doing that until the more fundamental bits of the game are done.
05/18/2009 (9:40 am)
Aww, health cheats much? ;) I do like the blood. Looks like the bots are pretty competent though, so it'd be a pain to keep getting killed while testing ;P.Watching these blogs is great inspiration... I'm itching to get into some AI work of my own. But I'm not doing that until the more fundamental bits of the game are done.
#5
I've been doing it to them for so long, though, I think they've been wanting to get their revenge
05/19/2009 (4:17 pm)
Quote:Wow, very nice, ill want see your kit with the combat starter kit... :DNow that would be a cool combination.
Quote:Cant wait to see what you have next!How about the next single player demo?
Quote:Looks like the bots are pretty competent though, so it'd be a pain to keep getting killed while testing ;P.YES! Especially now that sniping is working...Do you know the embarrassment of being shot in the head by a CPU player 200m away?
I've been doing it to them for so long, though, I think they've been wanting to get their revenge
#6
05/20/2009 (7:17 pm)
Work on the guns, and you got some serious moola in your back pocket.
#7
05/20/2009 (7:35 pm)
I'm not worried about the guns as much as I am worried about the AI. I'm going to be releasing the single player demo very soon, what weapon suggestions do you have?
#9
Could you please email me at ken.finney@tubettiworld.com ...?
Thanks!
06/01/2009 (10:58 am)
bryce, Could you please email me at ken.finney@tubettiworld.com ...?
Thanks!
#10
06/05/2009 (7:28 am)
Bryce, check your email!
Associate Steve Acaster
[YorkshireRifles]
Sounds like you're going great guns.