The "Soldier" AI


Hey again!

So, I decided to talk a little about the "soldier" AI that I wrote for this game. It's still a work-in-progress and I'm still polishing up the animation portions of it and things like that, just to make it look better to fight against.

Let me start off by saying that this AI is written with a different goal in mind, than what we usually think about AI in games, and especially shooters. It will try to survive, for as long as it can. Its main job is not just to line up in front of you so that it can die, making you feel like the hero.

This means that the AI will try to evade the player when they're in a bad situation. In a more real scenario, they just make sure to move around a lot and avoid places where the player was seen unless that is their strategy (as flanking and organizing push tactics.)

I've broken this AI down to what is basically modules. It works, not alarmingly, like a state machine. Every state puts the AI into a certain type of behavior. 

We all know that a game AI is only as good as how much information we can give it about its surrounding. To address this I have a few simple sensors in place. Firstly I have a loose distribution of so called "cover nodes" around in the level. These nodes are polled by the AI to find suitable places to run to.

Not only that, we can tell the AI to specifically poll nodes that are seen by the player, or seen by them, or neither, or both, to make them do interesting things with this limited data-set.

Another sensor I have in place are so called "overwatch/sniper positions". These work pretty similar to cover nodes. The AI can check to see which of these overwatch nodes overlook something interesting, such as the player.

Here's a picture of several AI in different overwatch spots, exaggerated for clarity of course.


(don't mind the green boxes in the trees, those are only VFX related. And also, the blue cubes are the cover nodes.)

The AI only camps out at these positions for a set amount of time. It also makes sure to provide some suppressive fire against the player once they've spotted us. To sort of mimic that they don't know exactly where the player is going to move, so they keep firing just to discourage. Suppressive fire is a behavior in itself of course, in which they spray bullets in the direction they last saw the player in. This can actually be quite effective to fence the player in.

Another thing that's great for fencing players in aaaareeee....


Grenades!

This is actually a pretty complicated calculation, making a grenade-arc that's accurate and I wish I had solved it to share it with you, the reader, but I didn't. I just winged it and it works well enough I guess. Let's just pretend the AI isn't super great at chucking metal cans full of combustible fuel that far. But I do try to make sure the AI doesn't peg it right at a wall as seen in some other games.

So I was talking about suppressive fire before. Well, that behavior works for the AI as well.

If we start shooting at them, and the bullet is close enough to them, they will sometimes just decide to take cover/stay put.


So the AI will sit like this for a while and eventually run off, at the moment though they don't really care if you still shoot at them so you could easily just snipe them to death from a far. Not ideal, but something I'm working on. I will also try to get them to not take cover in the open like this, unless I make a variant where it lies down on its belly or something that makes their silhouette smaller.

But how do we even know that a bullet was close?

Let's just let physx help us with that.


This sphere(cheapest shape available heyooo!) reacts to the bullets, but only tells the AI that someone hit it with said bullet. It doesn't collide with anything else. There's some other things we could use this for,  but for now that's it.

This small behavior alone is pretty cool and most importantly, useful for you, as the player. AI giving you trouble from a far, just unload in their general direction and they just might run off/sit down and leave you alone a while.

And before I round this off, there's some behaviors that are harder to show in pictures and surprisingly hard to record footage of as well. Maybe I'll do another post once the AI is a bit more complete trying to showcase some further things.

I have a primitive flanking behavior, and a grouping behavior and I want to ideally get some squad-type behavior in as well which would be cool inside the city/building area of the level and I have some ideas already on how to do this. We'll see.


In closing, the AI mostly just likes to bleed just as much as we like to shoot them.


(yes, this is mostly because I reworked the blood effect)

Laters!

Get "P4" (Untitled game)

Leave a comment

Log in with itch.io to leave a comment.