Game Development Community

Tactical AI Kit: Squads

by bryce · 07/24/2008 (6:48 pm) · 25 comments

Hello GarageGames,
I can easily say this is the biggest accomplishment with this project I've ever made in just one week. Yes--I have squad support working. None of this is scripted (by not scripted I mean the AIPlayers don't just advance when the player enters a trigger, like in Call of Duty). Read on.

How does it work?

At the moment, I've made a scriptObject called Squad1. This script object is added every time the developer adds an AI squad.
function Squad1::Create(%leader,%m1,%m2,%m3) // This squad consists of a leader and three other members
{
  %squad = new ScriptObject(Squad1) {
    member[0] = %leader;
    member[1] = %m1;
    member[2] = %m2;
    member[3] = %m3;
    numMembers = 4; // Four-person squad
    
    objectiveType = "None"; // ObjectiveTypes, for now, are Move, Contact, and None.
    objectiveData = 0; // Depending on the ObjectiveType, this can be either a position or object id.
    
    moveLocation = ""; // A place we should move to that isn't part of the objective. Move towards a sound, onto a foot switch, whatever.
    
    currentOrder = "Regroup"; // Can be Regroup (follow), Hold, Move, and Objective (fulfill the objective)
  };
  %squad.onCreate();
  echo("Squad1::Create--" @ %squad);
    return %squad;
}

Squad1 can hold a maximum of 4 members (There's no hard-coded limit--just add more member variables and increase numMembers to your liking. Make 'em storm the beaches of Normandy!). Member[0], the first member, is the squad leader, which can be both a human or AI player. The squad leader makes all of the decisions, and the other three members follow those orders (orders show up on a human player's screen using CenterPrint).

The ObjectiveType and ObjectiveData fields define the objective for the squad leader. By setting ObjectiveType to Move and ObjectiveData to the position of, say, the center of the enemy base which they need to capture, the squad leader will decide if he should pursue the objective. If so, he will set currentOrder to "Objective". CurrentOrder is the variable that the other three AI Players read--Once they see a new order, they will execute it. If the squad leader is a human player, there is a key command to set the order to objective. Each member regroups with the squad leader, and the calculates a path to the objective.

So, you can start off a squad of ai players moving towards an objective by typing this into the console:
$n = Squad1::create(spawnai(1),spawnai(1),localclientconnection.player,spawnai(1)); $n.objectiveType = "Move"; $n.objectiveData = ObjectiveMarker.position;
This will create three AI players and link the human player to the squad. Once all of the players are within 10 meters of the squad leader (regrouped), they will move to the objective.

But what if they come under fire?

If the squad members know where the enemy is that is firing, they will fire at full rate (suppressing fire) at the enemy to either kill him or force him behind cover so the squad can get to cover as well. If the enemy is close enough and there are no others around, the squad leader will have the next living member under him go and flank (sneak up on) the enemy. When the enemy is dead, the squad regroups and proceeds toward the objective.

How do they avoid ambush?

A real-life squad is asking to be cut down by enemy fire if they move towards the objective completely out in the open. So, last night I thought up a cover-to-cover movement system. Using my awesome Paint skills, I'll demonstrate.

img385.imageshack.us/img385/5218/imgazl4.jpgimg92.imageshack.us/img92/2726/imgbhf5.jpgimg175.imageshack.us/img175/5401/imgcsk6.jpg
Image A--The movement area. The green X is where the squad starts, the red X is the objective. The blue line is the path, and the black squares are randomly scattered crates, which are used for cover.

Image B--Every 20 meters a squad member travels, a point is calculated 50 meters forward in the direction they're moving. This is the guess of where an enemy engagement could possibly occur. The arrows show the location of each check. Each squad member will move to cover from that forward position, if there is cover. The cover locations chosen are the tiny purple dots.

Image C--After moving to cover and seeing that there are no enemies in that area, each member will recalculate the path to the objective, and keep performing the cover search again every 20 meters. Image C shows the resulting path.

I implemented this system this morning, works without a problem. It's getting hard to kill these guys, I've had to triple my player datablock's maxDamage field just to stay alive. That doesn't even help me much...
Screenshots:

img440.imageshack.us/img440/5328/screenshot00100001nu3.png1. The squad leader ("V") and the two other members ("O") waiting for you to regroup with them so they can go.
img242.imageshack.us/img242/3621/screenshot00100002ls5.png2. Once regrouped, we move to the objective.
img176.imageshack.us/img176/3599/screenshot00100003rk7.png3. ....and move....
img99.imageshack.us/img99/9642/screenshot00100004de1.png4. We've arrived at the objective, so we need to regroup.
img182.imageshack.us/img182/5842/screenshot00100005ti3.png5. An enemy squad of three regrouping to storm your base.
img363.imageshack.us/img363/5430/screenshot00100007ol5.png6. The squad advancing over the hill.
img370.imageshack.us/img370/5385/screenshot00100008qu1.png7. Coming under fire. If the player fires back, the squad will move to and appropriately use cover. If the player hides again, the squad will continue advancing, but will always watch the position where the player was sighted last.
img170.imageshack.us/img170/5824/screenshot00100013mr2.png8. Here you can see the enemy squad leader crouching to reload as he runs to his barrels for cover. The other two members are already there, waiting for the player to expose himself (they started firing at me right after I took the screenshot; you can see a little yellow streak of a tracer bullet coming out of the left guy). You can see the reason I only added a 3-man squad instead of a 4-man squad. I was just too lazy to add another cover object down there. If you're wondering, an AI Player that cannot find any available cover will just crouch down and fire at the enemy until something's available--He will still be able to flank if the squad leader needs him to.

A video:
www.youtube.com/watch?v=G9Cm8qLL39s

Rate and comment! I'm open to questions.
Page«First 1 2 Next»
#21
07/25/2008 (10:30 am)
Battlefied Kork FTW
#22
07/25/2008 (9:58 pm)
Bryce,

Really like where this is going, would be able to use it in my upcoming game for the AI in Torque Titans. Have you considered releasing the content pack as a "Beta" or something like that? This way we could get it working in our games, you get paid and we could get updates as you bring them forth. That way, we, as a unit, or group of users could get on a forum here or at your site and keep feedback coming and ideas rolling in for the pack... something like now but on a bigger scale. I know I would buy the pack. What do you think of this idea? And what do you think the cost will be for the pack when it does become avalable? Think we will see a release by xmas 08? Just wondering, and keep up the great work man, looks sharp.

Will
Digital Lightstorm Studio
Waskom, Tx
#23
07/25/2008 (10:12 pm)
Cool beans! Really nice stuff
#24
08/02/2008 (1:57 am)
@Will--I'm working on a demo which I'll try to release before September. A Christmas release seems pretty doubtful at the moment, there is still a lot of things I am planning on implementing in the pack and the AI is still missing some important things, such as squad membership changing (changing which AI player becomes the team leader if the team leader dies) and reacting to threats.
#25
08/11/2008 (5:12 am)
Very nice work bryce.
Page«First 1 2 Next»