# RPG Chance to Dodge formula

A friend and I are trying to develop a “chance to dodge” formula that will scale from level 1-1000. I would like to see if one formula can be utilized, using a difference ratio between Character A’s level and Character B’s level. The factors involved in the equation are as follows:

Dexterity (Max 38)

Acrobatics Skill (up to 5 possible skill points)

The equation in theory:

(Acrobatics Skill * 5) + ((Dex - 10) * 0.1) + ((CharacterB's Level - CharacterA's Level) * 0.1)

The formula has been varied a little to make it work better in one regard which has the inverse effect of making it not work in another area. For example, the formula may work and scale well if a lvl 700 is striking at a lvl 1000. Let’s say that works out that Character B has a 65% to dodge. Sounds good…..except if the same formula is applied to a lvl 5 is striking a lvl 20 (low levels).

We don’t want there to be a 100% chance to block. Then again, I guess if a level 1 struck at a level 1000, that would be a little bit ridiculous that he would succeed. But once again, it would be nice if there was a way to scale the entire level spectrum by use of perhaps cosine and the difference-between-level’s ratio.

• Why are you multiplying dex - 10 by one? – Cameron Fredman Mar 14 '13 at 2:19
• Meant to be a .1 – rpgguy Mar 14 '13 at 4:25
• You have one thousand levels? Why? At that point, will anyone even notice going from level 88 to level 89? Are they going to particularly cherish or even remember when they hit level 123? At this point, you may as well be using a point-buy system rather than a level system. – Nicol Bolas Mar 14 '13 at 7:16
• @NicolBolas Well, in Disgaea you can go up to level 9999, and do damage in the billions per hit. It is ridiculous, but quite fun. – David Gouveia Mar 14 '13 at 10:15
• I'm not clear why you're factoring the level in at all. If you have two stats (acrobatics and dexterity) which affect chance to evade, presumably a character leveling has the opportunity to improve those stats. If they haven't or aren't, why should their evasion ability improve? – Cameron Fredman Mar 14 '13 at 17:48

It all depends on how you want your function to scale:

Seems you need a function of AttackerLvl/DefenderLvl and something like 1/x for scaling it, or maybe a function of DefenderLvl/AttackerLvl and scale it according to a sqrt( x) or x^2 function. The only stuff you have to be cautios about is to make sure those functions intersects the starting and ending points that you desire:

In example:

• You may want to scale it so that at Maximum attacker level( 1000) minimum defender level(1) the dodge chance is minimal (5% / 0.5% / 0.1%)
• You may want to scale it so that at Minimum attacker level(1) and maximum defender level(1000) the dodge chance is maximal ( 95% / 99.5% / 99.9%)

So in example if you want to go with sqrt(x)

You have to solve the system first:

• Equation1: a*sqrt( 1000+b) = 0.95
• Equation2: a*sqrt( .001+b) = 0.05

and find out what "a" and "b" values are.

In this case:

// return a number between 0.05 and 0.95
double dodge_chance_on_level( double defender_level, double attacker_level)
{
double x = defender_level/attacker_level;
double a = 10.0/ sqrt( 111111.0);
double b = 111071.0/ 40000.0;
return a*sqrt( x+b);
}


Don't warry, you don't need to be profitable in math, you just need to copy paste those equations into a non-linear system solver.

The output for the function is:

dodge_chance_on_level(1000,1)=0.95
dodge_chance_on_level(100,5)=0.143175
dodge_chance_on_level(20,10)=0.0655675
dodge_chance_on_level(10,20)=0.0543056
dodge_chance_on_level(5,100)=0.0504391
dodge_chance_on_level(1,1000)=0.05


Seems not very clever, but you just have to use another function (probably a linear function will works better in your case: it all depends on what you want, I just showed how to develop your own function).

Then you want also to design a function that scale with Dexterity and add the result to dodge chance.

Have a look at the Logistic Function (family). It maps the entire number line into [0, 1], which is exactly what you want for a probability.

Something like 1 / (1 + exp(M1 + M2 * (Defender's Level - Attacker's Level) - M3 *(Attacker's Accuracy) + M4 * (Defender's Dodge))), for some M1, M2, M3, M4 such that the "Equal levels" hit chance is where you want it, and your other parameters are worth a sensible "level difference"

there's easy formular, think easy :D

accurate = A.dex * 0.1;
evasion = B.dex * 0.05 - totalWeight(items)*0.5;
chance = ((accurate - evasion)/accurate)*100;
if(chance < 0)
return miss;
else if(random(100) > chance)
return miss;
else
return hit;

• This is an absurd suggestion. It is commonly implemented in most games as Accuracy/Evasion. Pokemon being a very good example. Although they actually do (AbilityAccuracy * (Accuracy/Evasion)) You would then also clamp the result to the minimum possible Hit percent, like 5-10%, and the maximum, which would be 100%. – Krythic Feb 21 at 1:14

Try using speed too. Just a suggestion:

(k1*attacker_speed + k2*attacker_dexterity) / (k3*target_acrobatics + k4*target_dexterity) * target_speed

k1, k2, k3 and k4 are values based on how much you want these values to increase depending on character level. I suggest you to change probabilities by using attack speed and range, changing it to:

(k1*attacker_speed + k2*attacker_dexterity) * attack_speed/attack_range / (k3*target_acrobatics + k4*target_dexterity) * target_speed