# HP damage equation, related to Armor

This topic is 2818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

HP = 100 // at start
Armor = 50 // at start

In my game hp damage can either be: 5, 10, 20, or 40. // depends if it is a headshot or a body shot.

I am trying to make a function so that when damage is received I have an equation that subtracts health depending on how much armor I have. If armor is close to 0 then I should take more damage to HP.

 public void healthDmgTaken (int damage) { hp -= (equation) } 

I tried a bunch of equations, such as (damage - (damage - armor)), but that does not work.

##### Share on other sites
So, to calculate how much damage needs to be taken, you can use something like (convert to floating point as needed):

damage taken = damage * (1 - armor / 50)

When armor is 50, no damage is taken. When armor is 0, you will receive the full damage.
Because teaching a man to fish is better than teaching a fish to human, I will also explain how I came up with that equation:

We want a formula that produces less damage with greater armor, and more damage with less armor. So, we can predict that we will want a negative armor somewhere:

damage taken = -armor

However, we won't be taking negative damage, so to keep it positive, we can add the max armor strength (note that max armor doesn't have to be 50. It should be whatever value of armor will cancel all damage):

damage taken = max armor - armor damage taken = 50 - armor

Now, we have a formula that will produce a number between 0 and 50. We want to make this between 0 and 1, so that we can multiply by the damage:

damage taken = (max armor - armor) / max armor damage taken = damage * (max armor - armor) / max armor

That results in the equation I gave above.

EDIT: Unless you just wanted the armor strength to be subtracted from the damage? In which case:

damage taken = damage - armor if (damage taken < 0) damage taken = 0

That 'if' statement is too ensure that you don't gain health from having too strong of armor.

##### Share on other sites

I am trying to make a function so that when damage is received I have an equation that subtracts health depending on how much armor I have. If armor is close to 0 then I should take more damage to HP.

I tried a bunch of equations, such as (damage - (damage - armor)), but that does not work.

It isn't a math failure: you need to choose your formulas and numeric values according to design needs that you don't seem to have figured out. In the case of combat, objectives and criteria might be:

• Most relevant to your question: if a character with a certain armour type and a certain amount of hit points is hit with a certain weapon, how bad should the wound be? None of the three quantities are on a numeric scale: armour ranges from "naked" to "light" to "typical for battlefield use" to "heavy and clumsy"; hit points range from "start of the game" to "what's expected at level N for class/race X" to "absolute maximum value of interest beyond which the system is allowed to break down"; wound gravity is measured in number of hits like this before dying, ranging from "nothing" to "don't even look at the hit point display" to "it hurts" to "serious threat if I don't end the fight fast" to "immediately lethal".
• In a fight between two characters with certain combinations of armour, weapons and hit points:

• What opponents is more likely to win, and by what margin? Is it who you want to have an advantage?
• Increasing armour by a certain amount compensates an increase of incoming damage: does this increase fit the progresion of weapons and armour? For example, if your gangster acquires his prized large-bore automatic shotgun late in the game with great expense and effort, but the standard-issue kevlar vest that my policeman character is likely to wear since the beginning of the game makes it less dangerous than a pistol, there is a serious game balance problem that can be solved by making the shotgun better and/or the kevlar vest worse.
• How long is the fight expected to be? (If too long or too short, the fight is boring.)
• In a fight between two characters with identical armour, skills and hit points, how much does attacking first affect the probability of winning the fight? How much should this influence increase or decrease at higher or lower stat values?
• What is the range of armour, residue opponent hit points, and other conditions in which weapon A is better than weapon B? No weapon should be unconditionally better than another, unless clearly presented as an upgrade or substitute.

##### Share on other sites
bpx95 and LorenzoGatti have covered nearly all of what I wanted to say, but I want to point out that (damage - (damage - armor)) is equal to the value of armor.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 13
• 30
• 9
• 16
• 12