Game Development Community

Opinions Sought: AI Aggression

by Michael Bacon · in Technical Issues · 10/09/2007 (3:47 am) · 7 replies

I'm just curious as to what others think about my ideas on ai.

I want each AI to be tweekable to have personality. Even if only in a minor way.

To this end I have added an Aggression Level to my AI.

Each AI has their own aggression level and each AI has an Aggression Level towards each other object. The AI determines the aggression towards another object in any way it sees fit (script callback, generally checking object type, team status, etc).

That gives us two values AI.aggressionLevel and AI.aggressionTowardsObj.

Next, I want my AI to be more aggressive towards things it finds more threatening. I plan to add a system to keep track of threats (usually a player but can be any object). Each time the AI is threatened by something (damaged or *whatever*) it will add the object and a threat level to the threat list. The values will get added up and tend to decay.

This gives me a third variable: AI.objectThreatLevel.
All of these values are clamped to the (0,1) range.

So.. I'm thinking that when all is said and done and my AI needs to decide it's current target I will add the object threat level to my aggression towards it (clamping again) and multiply by my aggression level. Do this for each potential target and pick the one that I am most aggressive towards.

Sounds like a plan or can any of you point me in a better direction?

My goal is to give each AI an aggression level and to give each object a threat level relative to each bot.

Later these values will also be used to determine other difficulty factors such as how accurate bots are or even how often they fire.

#1
10/09/2007 (7:57 am)
I assume that in the end, you'll use these weights to determine which object the bot attacks. here are some other variables you may want to consider:

-distance to the object
-most recent attacker
-current health level of the object
-vengeance factor(how many of the bot's allies has this object claimed)

sounds like youre off to a good start.
#2
10/10/2007 (6:35 am)
:) I hadn't thought about the last two. Thank you!


Basically I have a routine that is run every so often (biased by an attention level) called "scanForThreats". This method is only called when I need a new target (I will stay focused on my current target until I loose it, it dies, or something else hurts me and I decide to change to it). scanForThreats does a container radius search. Start the target as no object and maximum distance and minimum aggression. For each object in range check if it is closer and if I have a higher aggression towards it than the last. Finally I make sure I can actually 'see' the object with field of view and (most expensively) line of sight (which is why its last). I will automatically pick the closest object that I can see that I have the most aggression towards.

Here is where I am planning to add the threat level which basically keeps track of past aggressions of any object it interacts with. I am intending both short-term and long-term values with appropriate decays that are summed together for the total threat level of an object. When the aggression decays the object can be removed from the threat list.

I also have a team messaging system in place (based on the MessageRouter resource) that allows be to recompute targets when a team mate is injured, dies, kills a target, etc. This is another place I need the threat level. Currently all I can do is either compute my own aggression towards the object or just blinding change to my team mate's target on certain events or if I don't have a target of my own. If I have the threat level (memory for aggression) I can better decide my target.

Eck, just thought about having to add a pre-thought to the AI that checks it's own health...

I want to look at the long term though. How am I going to keep adding in these tasks?? When I have to decide on running for health or completing an objective that is five feet away. I need a way to track and weight my objectives. Right now its all hand-coded. Gotta add a state machine I would suppose but I'm not quite sure where to begin with that.

And I'm not quite sure exactly how to scale the threat levels. I want to keep it in a 0..1 range for simplicity. Maybe a -1..1 to allow friendliness? If you heal an AI a bunch maybe it won't kill you... Unless you killed one of its team mates or started attacking it. I was thinking that I need both short term and long term threat levels to keep track of very important transgressions (like killing a team mate, though I hadn't thought of it specifically like that).

I can't wait to add hearing. That should be much easier.
#3
10/10/2007 (6:57 am)
On the teams bit:
Might also want to consider stubbing in an over-arching strategic ai system for flocking and dispersion based on how many of each bot there is per team (ie, clumping up when overmatched to focus fire in an area vs spreading out from one another to disperse the search for enemies) as well as general locus of interest algies so they all try and head in the same general direction as a simple simobject that all members of that team refference (so you only have to calc that once per ai tick. general rule of thumb: half of ai programmings not really making them intellegent, so much as "dumb" in the right ways, so that you can run quickly adaptive code as well as deeply realistic behaviors. After all, bot vs bot calculations aren't linear equasions as the count goes up, more like quadratic. Just something to keep in mind)
#4
10/10/2007 (4:05 pm)
Sounds alot like threat and aggro in an MMO, so you know it's a good system. Since it sounds like the bots aren't JUST trying to be strategic with their attacks, but really pissed too :p you might want to create some way, algorithm or something to figure out the chance to attack a certain target when many are in sight based off both strategy (who's easiest to kill) and aggression, this if player1 killed the entire AI's team, and player2 does nothing, AI will try to attack player1 even if he is much farther away. "Revenge!!"
#5
10/10/2007 (4:55 pm)
Thats great! I hadn't thought about "strategy" yet (ya, I'm a dope) I focused too much on instincts.

A strategic mind for both the bots themselves and an over-mind for the team AI. I'm considering making the Player and AIPlayer too at this point because then I can use all of my methods to direct the player character when I don't want the user to have control.

That just set off a spark of ideas. Thank you both!
#6
10/19/2007 (3:54 pm)
Wow, this thread really sparked my own imagination!

Would it be possible to run an entire gang of orcs using the "Revenge!!" mind-set?
#7
10/20/2007 (5:04 am)
Why not? I've got most of this already baked into my AIPlayer so yeah, I can spawn a bunch of them and let them go.