Trending
Opinion: How will Project 2025 impact game developers?
The Heritage Foundation's manifesto for the possible next administration could do great harm to many, including large portions of the game development community.
Featured Blog | This community-written post highlights the best of what the game industry has to offer. Read more like it on the Game Developer Blogs or learn how to Submit Your Own Blog Post
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.
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
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
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
You May Also Like