0
\$\begingroup\$

I am an amateur using Unity 5 to create the aforementioned type of game. I am trying to write a function to determine whether a close quarters combat(melee) attack lands or not but am extremely terrible at math. How bad? Despite tutoring for 2-3 hours every day after class and doing my homework assignments multiple times for practice even after submitting them, I still failed business calculus 3 times and had to abandon college. Math simply does not click for me. I found a sweet sales job in the booze industry so it's all good though, but I digress. If anyone could humor me and point me in the right direction I would appreciate it. Here are the details, let me know if I'm being inarticulate.

  • Combat is turn based, in the same vein as Ogre Battle, Heroes of Might & Magic, and Final Fantasy Tactics. Hopefully this gives you an idea of movement and engagement, if not let me know and I'll elaborate with specifics.

  • Whether or not an attack lands is determined by (what I'll call for simplicity) the two combatants "Weapon Proficiency." This system is based on a 100 percentile system. For Example, if both attacker and defender have a Weapon Proficiency of 50, then the attacker has a 50 percent chance to hit the defender.

My issue is I have no idea how this mathematical function works when weapon proficiencies are of disparate values. For example, if the attacker has a weapon proficiency of 35 and the defender has a weapon proficiency of 85, what percent chance does the attacker have of scoring a hit?

Any help would be extremely appreciated, again forgive me if I'm not explaining the subject lucidly.

\$\endgroup\$
4
  • 3
    \$\begingroup\$ "For example, if the attacker has a weapon proficiency of 35 and the defender has a weapon proficiency of 85, what percent chance does the attacker have of scoring a hit?" How much chance do you want the attacker to have? It's your game, your rules. It's possible to construct a formula to give whatever result you choose, but so far your question doesn't have enough detail for us to suggest one, because you've only given us one data point of your desired result. There's no universal "to-hit" formula we'd apply by default - this kind of calculation is resolved differently from game to game \$\endgroup\$
    – DMGregory
    Jan 5, 2016 at 22:36
  • \$\begingroup\$ I must be poorly presenting my question and not giving enough detail as you have said, I apologize. I am a total noob, but I wasn't under the impression there was a "universal to-hit formula" and am aware every game designer calculates this differently. I'll try and think of a way to better pose my question. \$\endgroup\$ Jan 5, 2016 at 23:27
  • \$\begingroup\$ No need to apologize - we're not blaming you, just trying to nudge you onto the path to the answers you need. I drew some diagrams to illustrate that there are many different behaviours that follow the "50 A vs 50 D = 50%" rule. Clockwise from top-left: 1. opposed roll with modifiers (like a D20 system), 2. Heckel's factor suggestion with factor = 0.4, 3. Heckel's ratio suggestion, 4. opposed roll where proficiency determines the size of the die. Many more patterns are possible, so you need to consider what you want to happen as the attacker & defender's stats vary \$\endgroup\$
    – DMGregory
    Jan 6, 2016 at 6:05
  • 1
    \$\begingroup\$ Another idea: go to a game store and check out some pen&paper roleplay games or tabletop battle games. The combat in these games are all about chance and proficiencies. You might get some idea's there. \$\endgroup\$
    – Felsir
    Jan 6, 2016 at 7:11

1 Answer 1

1
\$\begingroup\$

There are a lot of possibilities. Here are two I can think of:

The attacker's weapon proficiency is attack and the defender's is defense. percentage is between 0 and 100, but it can easily be modified to be between 0 and 1.


percentage = attack/(attack + defense) *100

Characteristics:

  • It can only get to 100% if the defense is 0. So no matter how good a weapon is it can still fail to any defense that isn't 0.
  • It can only get to 0% if the attack is 0. Even if the defense is very good it can still fail.
  • It depends on the ratio of attack/defense. Which means that the percentage is the same if the attack is 100 and the defense is 10, or if the attack is 1000 and the defense is 100.

percentage = 50 + (attack - defense)/ factor
if (percentage > 100)
    percentage = 100;
if (percentage < 0)
    percentage = 0;

Characteristics:

  • The percentage can get above 100% or below 0%, so you have to check it. It also means an attack can be so much better than a defense that it is sure to hit, or a defense can be so much better that it is sure to block.
  • You can tweak the result by changing factor, to get the results you want.
  • It depends on the difference of attack-defense. Which means that the percentage is the same if the attack is 100 and the defense is 50, or if the attack is 200 and the defense is 150.

If they don't fit your needs, feel free to comment why to help us define what you are looking for.

\$\endgroup\$

You must log in to answer this question.

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