1
\$\begingroup\$

There are a ton of these questions, some can get really mathy - which is fine, but I am looking for a simple way based on a few stats, I thought I came up with one, so I will share it in hopes that someone can tell me where I might be going wrong.

The goal is that the monster should, depending on how powerful you are, be able to have a chance to hit. Weaker monsters instant death to them, harder monsters possible instant death to you.

I also realize these are hard questions to answer because it is game dependant. I hope I have provided enough info for you to give some guidance.

Lets get the stats out the way:

  • To Hit Stat (Character): base stat / modded stat (ie: 12/100)
  • Accuracy / Dodge (Character): between 0.0001 - 1.0 (0.01% - 100% (can be higher))
  • Enemy Dodge / Enemy Accuracy: Between 0.0001 - 0.85 (0.01% - 85%)
  • To Hit (Monster): Dex / 10,000 - where 10k is 1k higher then max stats (9k) for monsters
  • Monsters do have a max level (if that will help)

When a character levels they get 1 point into their base stat - which is then used in conjunction with all equipment and so on to increase the modded stat additively (base stat + base stat * bonuses = modded stat)

Characters can cap out (Modded stat) Higher then 10K which might pose issues for a to hit formula. How ever at that point I would assume your skills are 100% as max level is 1000 - thus you should always be hitting

The idea I had was (based off another question asked):

(stat / modded stat) + (((accuracy - dodge) / accuracy) * 100)

Some assumptions I made based on how I built the system:

  • Accuracy at 100%+ means you always hit
  • Dodge at 100%+ Means you always dodge.
  • Enemies dodge and accuracy do not go above 85% (they can start at 0.01% for both)
  • Monsters always use their dex (ie 12/max cap), monsters do not have modded stats
    • All Monster stats are the same, IE: if Dex is 9k all other stats, such as str, int, chr ... are also 9k

There are some issues with this formula though:

  • If stat and stat mod are the same (no equipment or bonus for character only) I chose to use the stat (as opposed to stat / modded stat) so, if 11 === 11 - well, use 11. For the character (see below for example)
  • Because a character might never train (I don't know why) Accuracy or Dodge their bonus might be 0.01% (there are equipment bonuses that can increase this to a max of 30% across all equipment with another 5% for boons (135% max) how ever in the following example we will assume you have nothing)

So:

   Level 1 (Character) = (11) + ((0.0001 - 0.0001) / 0.001) * 100) = 11 // Nothing equipped no bonuses

   vs.

   Rat (Enemy) = (8/10000) + ((0.0001 - 0.0001) / 0.001) * 100) = 0.0008

This doesn't seem right, so the player has a 11% to hit and the rat has a 0.0008% chance to hit?

Character : 100 - 11 = 82% chance to hit Rate : 100 - 0.0008 = 99.9992% chance to hit?

This doesn't make sense to me. For context here's a high level monster with a character that has a 95% dodge chance:

 (9000/10000) + ((0.75 - 0.95) / 0.75) * 100) = -25.7666666667

That does not look right.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ When both accuracy and dodge are 100%, what should happen in your system? \$\endgroup\$
    – Theraot
    Aug 4, 2021 at 10:31
  • \$\begingroup\$ I don't understand why you would calculate your hit stat based on base stat / modded stat. What's the design intention behind that? \$\endgroup\$
    – Philipp
    Aug 4, 2021 at 10:35
  • \$\begingroup\$ And what is the conceptual difference between "to hit" and "accuracy"? Why have two stats which apparently represent the same thing (likeliness to hit your target)? \$\endgroup\$
    – Philipp
    Aug 4, 2021 at 10:42

1 Answer 1

2
\$\begingroup\$

I'm going to give you a few options to handle accuracy and dodge, pick the one that better suits you. I have no idea about the other stats.


Accuracy is paramount

For our first option, if an attack has 100% accuracy, dodge does not matter. Even if dodge is 100%, when accuracy is 100%, dodge does not matter.

In fact, the probability of hitting are at least accuracy. That is, the formula will be accuracy plus some other term.

This is the formula:

probability = accuracy + (100% - accuracy) * (100% - dodge)

Of course, the second term is a function of dodge. I made it 100% - dodge because less dodge should be easier to hit. Also, it has a factor of 100% - accuracy. The idea is to scale down the effect of the second term as accuracy increases.

With this formula, the only case where it is impossible to hit is when accuracy is 0%, and dodge is 100%. Furthermore, you get perfect chance of hitting when either accuracy is 100% or dodge is 0%.


Notes:

  • If you use 1/x instead of 1-x your distribution will be asymptotic (probabilities approach infinity, and of course you have division by 0). Don't do that.
  • The formula might have problems when a variable goes over 100%. Because 1-x would be negative. If accuracy is less or equal to 100%, clamp dodge to 100%. If accuracy is greater than 100%, you can either clamp both to 100%, or only clamp dodge to 100% - accuracy/(100% - accuracy), which allows values of dodge over 100% result in less probability than accuracy.

Dodge is paramount

When dodge is 100%, there is no chance of hitting. Even if accuracy is 100%, when dodge is 100%, accuracy does not matter.

For this formula, accuracy means more chance of hitting, insofar dodge allows it. In fact, the probability of hitting will never be greater than 100% - dodge. And we accomplish that by using it as a factor for accuracy.

This is the formula:

probability = accuracy * (100% - dodge)

Here the only way to have perfect chance of hitting is when dodge is 0% and accuracy is 100%. If either dodge is 100%, or accuracy is 0% it is impossible to hit.


Note: Here we also have a case of 1-x. However, being a formula of a single term, your options are to clamp both variables to 100%, or clamp the result (which is how you would handle negatives).


Generalization

So, you want something kind of in the middle?

This is the difference of the two formulas:

nuonce = accuracy * dodge + (100% - accuracy)(100% - dodge)

Now you can explore a continuum between the two formulas like this:

probability = accuracy * (100% - dodge) + nuonce * f

Where f goes from 0 to 1.

Regardless of f. When accuracy is 100% and dodge is 0%, it always hits. And when accuracy is 0% and dodge is 100%, it is impossible to hit.

When f = 1 you get the first formula, and when f = 0 you get the second. Furthermore, f is the probability when accuracy and dodge are both 0% or when they are both 100%.


There is an special case: When f = 0.5, the formula is a plane (for all other values, we have an hyperbolic paraboloid a.k.a. a saddle). For f = 0.5 the formula simplifies to this:

probability = 50% * (accuracy - dodge + 100%)

As you can see, in this special case, you get 50% whenever accuracy and dodge are equal (not only when they are both 0% or both 100%, which is true for any value of f).


Skewing

If you want to control the probability when both dodge and accuracy are 0% independently of the probability when both dodge and accuracy are 100%, there is a way. Notice that the formula I gave you for nuonce has two terms:

nuonce = accuracy * dodge + (100% - accuracy)(100% - dodge)

I could have expressed the difference multiple ways, but this terms has a meaning. It will be clearer here:

probability = accuracy * (100% - dodge)
    + p * accuracy * dodge
    + q * (100% - accuracy)(100% - dodge)

Now p is the probability when both accuracy and dodge are 100%. And q is the probability when both accuracy and dodge are 0%.

All that is missing is for you to decide.

\$\endgroup\$
4
  • \$\begingroup\$ This is very helpful, The only issue is it does not solve the issue of using stats. (ie: Stat mod and dex) its completely skill based, making your (character) "to_hit_stat" and the monsters dex completely useless. But does give me a good starting point to understand which direction to go. \$\endgroup\$
    – Kyle Adams
    Aug 4, 2021 at 19:36
  • 1
    \$\begingroup\$ @KyleAdams I have no idea what stat mod, dex, and to_hit_stat should do or relate to each other. If you have some examples of inputs and output, perhaps I can figure out something. Accuracy and Dodge is the only part that made some sense to me, and even there, I still don't know what the probability of hitting should be when they are both 100%. \$\endgroup\$
    – Theraot
    Aug 4, 2021 at 19:59
  • \$\begingroup\$ It seems like I am not the only one who can't make any sense of that. @KyleAdams If you answered the clarification requests I posted on the question, then you might get more relevant answers. \$\endgroup\$
    – Philipp
    Aug 6, 2021 at 10:17
  • \$\begingroup\$ I was going the wrong way, this actually works for my use cases \$\endgroup\$
    – Kyle Adams
    Aug 6, 2021 at 14:40

You must log in to answer this question.

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