Categories
AI Design Tutorial

Bot AI for a Single Player First-Person Shooter

This is one of many possible schemes for the AI of an enemy NPC in a first-person shooter game.  As written, it should (disclaimer: have not coded it yet) be fairly straightforward to translate it to a UE4 blackboard, behavior tree, and tasks, services, and decorators.

Tunable Parameters (and defaults):

Health A: [100, infinity)

Health B: [60, 100)

Health C: [30, 60)

Health D: (0, 30)

Health F: 0

 

Total Ammo A: [100, infinity)

Total Ammo B: [60, 100)

Total Ammo C: [30, 60)

Total Ammo D: (0, 30)

Total Ammo F: 0

 

Focused Ammo A: [100, infinity)

Focused Ammo B: [60, 100)

Focused Ammo C: [30, 60)

Focused Ammo D: (0, 30)

Focused Ammo F: 0

 

Focused Weapon A: [100, infinity)

Focused Weapon B: [60, 100)

Focused Weapon C: [30, 60)

Focused Weapon D: (0, 30)

Focused Weapon F: 0

 

Focused Powerup A: [100, infinity)

Focused Powerup B: [60, 100)

Focused Powerup C: [30, 60)

Focused Powerup D: (0, 30)

Focused Powerup F: 0

 

Focused Charge A: [100, infinity)

Focused Charge B: [60, 100)

Focused Charge C: [30, 60)

Focused Charge D: (0, 30)

Focused Charge F: 0

Effective Attack Range[current weapon]: min: float, max: float (for each possible weapon)

Distance Forward of Focused Enemy: 400

Distance Backward of Focused Enemy: 400

Distance for NEAR: 4000 (at most)

Distance for FAR: 10000 (at least)

 

Bored.Mu: 60

Bored.Sigma: 20

 

Variables:

Health: float

Total Ammo: float

Focused Ammo: actor, status

Focused Weapon: actor, status

Focused Health: actor, status

Focused Powerup: actor, status

Focused Charge: actor, status

Focused Enemy: actor, status, bInAttackRange

Focused Teammate: actor, status

(status:  NEAR, SUSPECTED NEAR, KNOWN, SUSPECTED, CLEAR)

Focused Enemy Forward: location

Focused Enemy Backward: location

Focused Waypoint: actor, status (only near, known, and clear allowed)

 

Variable-like properties:

bNearTeammateNeitherAttackingOrFleeing =  task != attack and task != flee and Focused Teammate.status == NEAR |SUSPECTED NEAR and Health > D and Total Ammo > D and Focused Teammate.task != attack and Focused Teammate.task != flee

bNearTeammateAttacking =  task != attack and task != flee and Focused Teammate.status == NEAR |SUSPECTED NEAR and Health > D and Total Ammo > D and Focused Teammate.task ==

bNearTeammateFleeing =  task != attack and task != flee and Focused Teammate.status == NEAR |SUSPECTED NEAR and Health > D and Total Ammo > D and Focused Teammate.task == flee

Bored

On enter a new task:  countdown = Gaussian(Bored.mu, Bored.sigma)

Loop: Countdown -= delta time

Emit True when queried if countdown <= 0 else emit False when queried

Break if leave task

Goto loop

Far From Home

Emit True when queried if no waypoint (accessible to this bot) is within FAR Unreal Units of self and there are waypoints for this bot, else emit False

Tasks

Here are the tasks the Bot can perform.  The conditionals for transitioning to other tasks are listed in priority order, that is the first is checked, then if no transition occurs, the second is checked, and so on.

Attack

(Action) Move toward enemy unless closer than Effective Attack Range[current weapon].min Unreal units, back up instead; Also move left or right randomly

Flee if Focused Enemy.status != CLEAR and (health < D or total ammo < D)

Collect Health if Health < C and Focused Health.status == NEAR|SUSPECTED NEAR

Collect Ammo/Weapon if Total Ammo < D and focused ammo/weapon status NEAR and can pick up ammo/weapon

Wander if Focused Enemy.status = CLEAR

Flee

(Action) Move away from enemy

Attack if Total Ammo.status >= D and Focused Enemy.status == KNOWN | NEAR and Health.status >= D and Focused Enemy.bInAttackRange

Collect Health if Health < C and Focused Health.status == NEAR

Collect Ammo/Weapon if Total Ammo < D and focused ammo/weapon status NEAR and can pick up ammo/weapon

Patrol if 10 seconds has elapsed

Wander if Focused Enemy.status == Clear

Patrol

Wander if no waypoints accessible to this bot

(Action) If there is a Focused Waypoint, move toward that waypoint

(Action) If at Focused Waypoint, choose another waypoint accessible to this bot according to waypoint-specific selection rules

Find Health if Health < C

Find Ammo if Total Ammo < C

Attack if Focused Enemy.status != CLEAR

Assist Teammate if Focused Teammate.status == NEAR | SUSPECTED NEAR and Focused Teammate.task == Attack

Defend Teammate if Focused Teammate.status == NEAR | SUSPECTED NEAR and Focused Teammate.task == Flee

Collect Health if Focused Health.status == SUSPECTED NEAR and health < B

Collect Health if Focused Health.status == NEAR and health < A

Same with weapon/ammo/powerup/etc.

Wander if bored

Wander

Find Health if Health < C

Find Ammo if Total Ammo < C

Attack if Focused Enemy.status != CLEAR

Assist Teammate if Focused Teammate.status == NEAR | SUSPECTED NEAR and Focused Teammate.task == Attack

Defend Teammate if Focused Teammate.status == NEAR | SUSPECTED NEAR and Focused Teammate.task == Flee

Collect Health if Focused Health.status == SUSPECTED NEAR and health < B

Collect Health if Focused Health.status == NEAR and health < A

Same with weapon/ammo/powerup/etc.

Patrol if Far From Home

Find Health

Collect Health if Focused Health.status == NEAR

Wander otherwise

Find Ammo, etc.

Collect Ammo if Focused Ammo.status == NEAR

Wander otherwise

Collect Health

(Action) Move toward Focused Health

Wander if Focused Health.status != NEAR (i.e. was collected)

Collect Ammo, etc.

(Action) Move toward Focused Ammo, etc.

Wander if Focused Ammo.status != NEAR (i.e. was collected)

Defend Teammate

(Action) Move toward Focused Enemy Backward

Flee if Focused Enemy.status != CLEAR and (health < D or total ammo < D)

Attack if Total Ammo.status >= D and Focused Enemy.status == KNOWN | NEAR and Health.status >= D and Focused Enemy.bInAttackRange

Wander if Focused Teammate.status == CLEAR

Assist Teammate

(Action) Move toward Focused Enemy Forward

Flee if Focused Enemy.status != CLEAR and (health < D or total ammo < D)

Attack if Total Ammo.status >= D and Focused Enemy.status == KNOWN | NEAR and Health.status >= D and Focused Enemy.bInAttackRange

Wander if Focused Teammate.status == CLEAR