Ive been developing an RPG for sometime, and its far enough now where I need to get some formulas down for attacking and whatnot. What Im looking to understand is a basic hit and miss formula based on dexterity or another stat. If someone can give me a basic framework to modify and extend, or helpful pointers, Id be appreciative.

  • 10
    \$\begingroup\$ if(random(1,100)>dexterity) { hit(); } else { miss(); } \$\endgroup\$
    – thedaian
    Jan 24, 2012 at 20:05
  • 3
    \$\begingroup\$ You should ask more specific questions, preferably with a short summary of what you tried and what you're struggling with. "Attacking and whatnot" or "based on dexterity or another stat" are not things that make it believable that you put any thoughts into this yet. \$\endgroup\$
    – bummzack
    Jan 24, 2012 at 20:30
  • 2
    \$\begingroup\$ This question seems related: gamedev.stackexchange.com/questions/14309/… \$\endgroup\$
    – bummzack
    Jan 24, 2012 at 20:32
  • 7
    \$\begingroup\$ There is no way that this question can be answered without knowing things about your game. Is it real-time, real-time-esque, or turn-based? Are there positional components like range and distance, or is it like Final Fantasy where anyone can attack anyone? What kind of gameplay are you trying to create? Do you want a combat system that rewards strategic play, or are you looking for more of a grind-based system? In short, your question is far too broad to answer as stated. \$\endgroup\$ Jan 24, 2012 at 20:38
  • \$\begingroup\$ @thedaian: That would make you less likely to hit as dexterity increases. Probably not what you should be going for. :) \$\endgroup\$ Jan 24, 2012 at 21:49

3 Answers 3


The formulas that you define are the game design for your game. You can specify whatever it is you want it to be.

You would probably do something like define a "base" hit rate based on your level compared to the enemy's level. Maybe have weapon expertise play a role (if that's a stat in your game). That kind of thing.

But if you want an example to work from, there are a lot of pages of people doing things like deconstructing the internal formulas in World of Warcraft. Like this one, for example: http://www.wowwiki.com/Hit


Here is a page with an equation to determine attack skill for Everquest. You may wish to follow the links on that page to other parts of the hit/miss/damage formulas. The formula has gotten very complicated over the years as the developers have added items that give bonuses to many of the secondary stats.


Mmmhh I hope I can help with the first thing that get's into my mind, and is something like this: I have an agility, that represents my characters ability to evade an attack. Then, in the other hand, I could have a dexterity or skill, or wathever status you would use to represent my character ability to succesfully hit an oponent. So, if I would like to keep things the most simple as possible, I'd say, well, if my ability to dodge is the same as your ability to hit, then, probably you would hit me the 50% of the times. That I think, would be my starting point. (I want to make clear that you would probably never hit me, but, that's not fun, at least not for games.) Right now I cannot think about hitting without necessarily knowing about my opponent's agility, cause, every case would be different, depending on what kind of enemy Im gonna hit., but, if your agility are same as my dexterity, I know you would hit me at least 1 of 2, and, if you are as twice as skillfull as me, I know you would surely hit me. Let us start with that premise in our minds.

Let's say that I have 12 dex., and I'm gonna hit you. You have 8 Agi. That said, I should have a good chance to hit you. So...using rule of three...

(Your agi) If 8x2 (16)----represents---100% chance I hit you. (I have to be at least two times as skillfull as you to hit you fure sure)

Then 12-----represents--- ((12*100) / 16) = 75% chance I hit you. That said, your chance to dodge me would be like 25% (Or chance that I miss)

75% and 25% are what it is for us, certain. But it does not end here, cause, well, those are chances, and you could still avoid my attack if I hit you, in spite you being weaker.

So we can add an extra random chance, to what for us is certain. I would do something like:

If((MyCharacter.CalculateChanceToHit(MyEnemy.GetAgi()) + (Usefullthings.GetRandomChance())) > 
(MyEnemy.CalculateChanceToAvoid(MyCharacter.GetDex()) +(Usefullthings.GetRandomChance()))
  MyEnemy.Dodge() /** Animate your enemy dodgin' like a pro.

Where Calculate chance to hit and avoid returns the result chance of that happening(three simple rule) and getrandomchance is just a function that may return any percent from 0 to 100, or 0 to 50, or whatever you like. Good thing is that, Getrandomchance gives you some control of what amount of "Lucky" you want to add to the game when chances are not on your side, and thinking a litlle bit too deep, you would have to try it several times to get what you think would be more "Fair". Its not cool that, If you have a more powerfull character, I got to avoid you many times, since it would seem like the "Certain" chance It's not really there. Im not a game developer but I think that would be enough, at least for a simple game., I guess you could add Some other chances like when you wear a weapon, I would make lances more reliable to hit somebody than a knife. Just a thought.


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