Sponsored By

Artificial Agent behaviors for Choosing/Switching Targets , Calculating Hit Chance

How an artificial agents should choose/switch target? How should I calculate threat of the enemy? How should you calculate the hit chance and decide if the target has shot or not? Here's one way of how.

Burkay Ozdemir, Blogger

March 4, 2013

2 Min Read
Game Developer logo in a gray background | Game Developer

A few months ago, I was searching through web about how artificial agents should switch target?, How should I calculate threat of the enemy? How should I calculate the hit chance and decide if the target has shot or not? and I’ve found almost “nothing”. So I decided to write some formulas according to my experiences in games and some real world situations.

I want to share them with you so that if you’re currently searching for same kind of thing you can find it right here!..

First lets look into threat calculation

Threat value is calculated for each soldier in the list of visible enemies by using factors below:
Distance to target
Angle difference between the defensive soldier and the enemy
The angle of the heading of the enemy and whether the enemy is firing or not
These factors are given different coefficients to balance the effectiveness of these factors in the threat level. So you can change the coefficients as you see fit.

Final formula generated by using these factors is

threat formula

  • DN is the distance normalized with maximum visibility distance.

  • If the enemy heading to the defensive soldier is lower than a minimum angle, A is 1,

  • otherwise it is 0.

  • If the enemy is firing, F is a constant value, otherwise it is 0.

Once you calculate the threat value for each seen enemy in the list, the enemy with the maximum threat can be chosen as the current target.

Lets get to the Hit Chance Calculation

To check if a shot is successful, a calculation is made based on the target distance, aim accuracy, the health of the soldier, whether the soldier is under fire or not and an additional random chance modifier.

With these bear in mind, the final formula is like this

hitchanceformula

  • DN is the distance normalized with maximum visibility distance.

  • AN is the angle difference between the aim of the defensive soldier and the enemy normalized

  • with minimum firing angle.

  • Ccoef is a coefficient depending on the cover status of the target.

  • If the soldier is under fire, U is a constant, otherwise it is 0.

  • Rnd is a random chance modifier.

  • chanceModifier is an external modifier that changes with incoming shots and the type of shooting being made (between 0 and 1)

If Hit Chance is above a certain value the shot is successful.

I think these formulas are simple and more than enough to calculate threat and hit chance for most of the artificial agent scripts. 

Hope these were usefull..till then.. For more.. http://programmerinstincts.com

Credits:
Burkay Ozdemir
Deniz Aladagli 

Read more about:

2013Featured Blogs
Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like