Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


RPG combat formula question

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is this the right forum for RPG combat formulas? In many RPG's there's a system to calculate if there'll be a hit or dodge with dices: attacker and defencer each roll a dice with as many sides as their attack / defence, and the one with the greatest number wins, so the attacker hits if he wins, or the defender dodges if he wins. But I'd like to know how to calculate the chance that the attacker will hit. I need this to use a similar formula as the two dice system, but for a weapon with continueous damage (a laser ). How to calculate that? Example: Attacker's attack = 80 Defender's defence = 70 Attacker rolls number A between 0 and 80, defender gets number B between 0 and 70, if A > B it's a hit, otherwise a dodge. What's the chance that it's a hit? Thanks. [EDIT] Additional question: Is there a better way to calculate how many damage of the laser should be absorbed? There are two spaceships, one with a laser that has a certain aim and damage, and another (the defender) with a shield + hull plating with a certain defence, what's a nice formula to calculate how much damage/sec the laser should do to the ship? I want it to still do zero damage if defender's def is infinite (never happens) or attacker's aim = 0, 50% of it's damage if def = aim, and 100% of it's damage if def = 0 or aim = infinite. [edited by - Boops on October 5, 2003 8:01:28 AM]

Share this post

Link to post
Share on other sites
Wait a second, when you say you want 100% damage if aim = infinite or def = 0, you mean that "or" to be an "and", right?

Assuming you do, this math is one of the critical balancing points of your game. Here's what I recommend for your starship scenario:

A = Accuracy rate of attacker (0%-100%)
E = Evasion rate of defender (0%-100%)
C = Chance to hit (0%-100%)
W = Power of attacker's weapon (0-Infinity)
H = Defensive power of defender's hull (0-Infinity)
D = damage done (0-Infinity)
T = Time of hull's exposure to laser (0-Infinity seconds)


C = A * (100% - E)

To understand this, remember that the Evasion rate is the reciprocal of the "Chance to be hit", so that an accuracy rate of 80% will hit 4 out of five times, and an evasion rate of 40% will GET hit 3 out of five times, while dodging two out of five times. So this example works out to the following:

C = 80% * (100% - 40%)
C = 80% * 60%
C = 48%

In this case, accuracy of 100% is no guarantee of a hit, unless the enemy's evasion is zero. I liken this to a perfect marksman, who can hit a bull's eye every time, but whose shots can still be dodged by a swift, clever target. An evasion rate of 100%, however, makes you a ghost, untouchable. If you don't like this, simply modify the equation to favor the attacker, like this:

C = A * (100% - E / 2)

EDIT: This can also be adjusted by simply allowing the accuracy rate to exceed 100%. With 1000% accuracy in the original equation, you're guaranteed a hit even against a 90% evade opponent, while a 100% evader is still unhittable. Just a thought.

Regardless, this is an instantaneous calculation, which might not be what you're after. If you want to work on the odds of breaking the "lock" or acquiring one after an initial miss, you'll have to reapply the formula at regular intervals. For a ten-second burst, calculate the to-hit formula ten times, and make the number of successful attacks equal "T".


D = ((W / H) / 2) * 100% * W * T

Here, the ratio of attack power to defensive power (W / H) is divided by 2 (This in response to your expressed desire that equally matched powers result in 50% damage) and then multiplied by 100% to get the damage percentage. This percentage is multiplied by the power of the weapon to get the damage per second, and that's multiplied by the number of seconds of exposure to find the total inflicted harm. That "* 100%" is purely cosmetic, since it amounts to multiplying by one, but it makes it easier to understand.

I didn't account for shields in this equation, because there are so many different systems of shield depletion and regeneration. Check out the thread on shield systems for some ideas.

[edited by - Iron Chef Carnage on October 6, 2003 5:12:11 PM]

Share this post

Link to post
Share on other sites
is it turn-based?
well, you talk about a laser with continous dmg, i guess not...


Attacker's attack = 80
Defender's defence = 70

Attacker rolls number A between 0 and 80, defender gets number B between 0 and 70, if A > B it's a hit, otherwise a dodge. What's the chance that it's a hit?

if using that formula, then the total number of combinations are 81*71 (since zero counts too)
Then it is a hit this amount of times...:

80and(70, 69, 68 ... 0) = 71
79and(70... ) = 71
(70and70 not, since A!>B)
70and(69, 68, ... 0) = 70
1and0 = 1
0and(70, 69, ... 0) = 0
then : {71*(80-70)} + 70(71)/2 = 3195 of 5751 = 55.555...%

if Att=10 and Def=20 (thus maxA
10and(20...10) = 0 ...BUT... 10and9 + 10and8...10and0 = 10
9and(20....9) = 0 ...BUT... 9and8 .... = 9
1and0 = 1
0and(20....0) = 0
then: 10(11)/2 = 55 of 231 = 23.8095...%

-> using zero:
if B>=A
{ {(B+1)*(A-B)} + B*(B+1)/2 }*100/{(A+1)*(B+1)} %
{ A*(A+1)/2 }*100/{(A+1)*(B+1)} %

those are the chances

oops, i forgot to simplify
if B>=A
(A -(B/2))*100 /(A+1) %
A *50 /(B+1) %

[edited by - giaym on October 8, 2003 7:19:03 PM]

Share this post

Link to post
Share on other sites
you could make a unit of measure, a shot, now, each time the ship does one, there will be an accuracy check, if the shot hits, a damage check.

Now some ships may make more shots per attack because its laser is faster... i dont know ... (in the case it is turn based)

Imagine you are in the ship, the laser is fired, that laser does 10 shots per second, the first shot hits... but the enemy can evade the other 9 if it was moving and just got hit on the "tail" or something like that... of course if you will do something like this, then the animation of the ships would be something a bit hard to show (Hit = H, Miss = X, then how do you...: HXHXHXHX , 10 shots per unit of time)

Unless there is no dinamic animation, just "Ship fired, it did 10 shots, 100 dmg". Or in the case you calculate all the shots for the unit of time, then get the total dmg done in that unit of time, then take the % of hits it did and select an animation of the attack using that % (100% -> the laser hits since the beginning and the ship had no chance to evade it, 10% -> the ship gets hit on the tail while evading, ...)

for the shields... well how do you want the shields to be in the first place...
You might have a shield that has an amount of energy, and they act as your only defense, once the shields batteries are depleted the ship starts getting using its plating as its only defense.
Or you might want a shield with some amount of energy available, but that can only bring some amount of protection (dmg reduction), the shields lose energy as dmg reduction they do.

Now you could do this dmg reducton like some screen that will always be there (until the energy runs out), thus it will reduce the dmg of the every shot that tries to go through it (in the case you use many shots per attack).
Or to make it like "water", punch the water your arm is the laser, water the shield, if you can go through it then it will stop offering resistance unless you retire your arm and have to punch the water again... So if the laser breaks the max dmg reduction of the shield (the shield still has energy though, but it has a hole now) the rest of the shots will not get dmg reduced by it.

In any of this cases the shield''s energy may regenerate and being completely functional again, for the amount of energy it has at the time, until it runs out again...

Share this post

Link to post
Share on other sites
Are you after any degree of progression across the game, I.E. the player''s characters get better against lower level enemies while difficulty against better enemies remains fairly constant? Because a system where you multiply percentages offers different resolutions for each number, for instance:

C = A * (100 - E)
90 * (100 - 20)% = 72
90 * (100 - 21)% = 71.1
91 * (100 - 20)% = 72.8
91 * (100 - 21)% = 71.98

Right there, we establish that a 1 point of Accuracy and Evade changes the base chance to hit ever so slightly. That change can add up over time...

140 * (100 - 70) = 42

Even 50 point increase there. 1 point of accuracy does not equal 1 point of evade, and as the two increase, the player has less and less chance to hit the enemies.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!