10
\$\begingroup\$

I'm making a game and I'm struggling with the formula to calculate the real damage the player does. I have skills which can do for example 10 hits of 20% weapon damage each of a total of 200% damage. Or another skill does 200% damage 1 hit.

However the formula I have right now is something like this

( 2 * Attack - Defense ) * 0.5

As you can see with an equal defense, the attack that does 1 hit 200% weapon damage will actually do more damage than the skill that does 10 hits 20% weapon damage each, because the reduction is greater when dealing low amounts of damage.

Or another case is a weapon does 200 physical damage and 50 fire damage. With this formula a enemy with 100 defense receives 150 physical (ok) and 0 fire damage (negative, not ok)

Can anyone help me get a formula (not too complex)? I don't know what to try. What I want to achieve is to get the same real damage (1 hit @ 200% or 10 hits @ 20%) and make the defense matter, what I mean by that is that it affects the attack.

\$\endgroup\$
3
  • \$\begingroup\$ With your current formula, you'll only do the listed attack damage if your target has no defense (in all other cases you'll do less), and will do no damage at all if defense is at least double the attack. Is that a rule you want to preserve, or do you want attacks to always do at least some damage/have the potential to do more than the listed amount? \$\endgroup\$
    – DMGregory
    Sep 1, 2016 at 22:32
  • \$\begingroup\$ I feel this question to be too broad. It depends, a lot, on all the circumstances. If you want 1 hit @ 200% or 10 hits @ 20% to be equals then you need to apply defense to the total damage, and not to each step. \$\endgroup\$
    – DH.
    Sep 1, 2016 at 22:32
  • \$\begingroup\$ I'm making a game as well and really like the original answer. One note that I had for the OP was; Wouldn't you want the 10 attacks of 20% damage to be a weak attack vs high defense enemies. I would assume a high defense enemy would require large, slow attacks to effectively take it down. At least that's how I remember most games working. Like you might use a fast, small damage weapon to take down low armor enemies, but it's not so effective vs large enemies (unless you have crit chance or something). \$\endgroup\$ Sep 16, 2018 at 17:50

1 Answer 1

17
\$\begingroup\$

When you want one hit with 200% attack to be exactly equal to 20 hits with 10% attack, then your only option is to make defense a percent value.

When the defender has 55% defense vs. physical damage, then the total amount of physical damage they receive is reduced to 45%, no matter how large or small the portions in which it gets dished out.

However, percentual defense has its pitfalls, especially in RPGs where you have a continuous progression. You can never allow to go above 100%, because then you have total invulnerability. Even getting very close to 100% is a balancing nightmare. The difference between 97% and 99% means the character can withstand three times as many hits, so an inconspicuous 2% defense buff can turn out to be a game-breaker. On the other hand, there is not much practical difference between having a total of 1% or 3% defense, so it is hard to still have a meaningful progression on lower levels.

A different formula used to calculate damage which you see quite often is:

damage = att * att / (att + def) 

The nice thing about this formula is that it scales without limit:

  • When attack and defense are roughly the same, there is roughly half as much damage as attack. This is true no matter how large the values are.
  • Even when the defense is pathetic compared to the attack value, there is never more damage than attack. This gives you an upper limit on how much damage a character can inflict, which makes balancing far easier.
  • On the other extreme, no matter how high the defense gets, it can never completely mitigate damage (except through rounding errors), so there is always room for improvement for the defender and there is never a completely pointless attack.

But you still have a bias for few, strong attacks over many weak ones. But the bias is lower the less defense the target has compared to your attack. This means that different attack strategies are efficient depending on whether you face an enemy with more or less defense. This usually adds depth to the game while still keeping it intuitive (a heavily armored enemy has to be cracked with a single, very powerful attack while a lightly armored enemy is more vulnerable to a flurry of weaker blows).

Also, you need to be aware that you get a result of NaN (or a division by zero error with integer arithmetic) when both attack and defense is 0, so you should not forget to handle that situation separately. You also get weird results when you insert negative values, so your character system should not allow negative attack or defense (when you want healing magic which uses the same formula, invert the sign afterwards).

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Solid answer, and I like that formula. :) But I do take issue with this line: "your only option is to make defense a percent value." The requested behaviour only requires that damage reduction obeys a distributive property, and there are many ways to do this. We could adapt your formula for instance and make it.... damage = skill_attack * (base_attack/(base_attack + defense)) - this way defense isn't capped, but the damage reduction multiplier is still consistent across skills with the same weapon, and so distributes as desired. \$\endgroup\$
    – DMGregory
    Sep 2, 2016 at 1:33
  • \$\begingroup\$ @DMGregory I have a question, is the skill_attack a percentage, or I could just make it the same as base_attack when attacking normal. And when using a skill if it's 200%, skill_attack = 2*base_attack \$\endgroup\$
    – marcg11
    Sep 2, 2016 at 8:36
  • \$\begingroup\$ Using the examples from the question: "I have skills which can do for example 10 hits of 20% weapon damage each of a total of 200% damage" here skill_attack = base_attack * 0.2, while "another skill does 200% damage 1 hit" would have skill_attack = base_attack * 2 exactly as you say. \$\endgroup\$
    – DMGregory
    Sep 2, 2016 at 11:13
  • \$\begingroup\$ "But you still have a bias for few, strong attacks over many weak ones"? My immediate first assumption as a player would always be that the skill multiplier directly affects final damage only; ie. damage = ((base_attack * base_attack)/(base_attack + defense)) * skill_multiplier. Would this not eliminate that bias for fewer higher multiplier hits entirely? Although, I do see your point about the intuitive depth. In that case; the armored enemy can't dodge well, so the powerful attack to crack it can afford low accuracy. The flurry needs high accuracy to hit the lightfooted unarmored opponent. \$\endgroup\$ Jun 6, 2022 at 2:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .