• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Is anyone good with formulas?

Status
Not open for further replies.
Level 8
Joined
Mar 3, 2009
Messages
327
Im implementing a kind of agility based hit-or-miss system. Basically, the hero's attack rating is calculated by their agility, and the unit's is calculated by level*X (at the moment X = 10 but thats subject to change).

If the attack ratings are equal, I'd like a 60%-70% chance to hit (again, subject to change) with an incremental bonus/penalty if one rating is higher than the other.

I know i could spend hours doing this an get nowhere, so I'd really appreciate it if someone could post with a good formula+explanation, thanks.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
You could use 100 * AR / sqrt(AR*AR + DR*DR)

Tha would produce 70,1% chance to hit when the values are equal.

Here's a table with attack ratings of 20, 40, 60, 80 and 100 to illustrate the chances:


Hit_chance_table.jpg

 
Level 8
Joined
Mar 3, 2009
Messages
327
Great maker, thanks!
Can't give you any more rep lol. IMO you should be able to rep others once every day..

EDIT: Hang on, what am I meant to randomize to find out whether the attack hits or not? :L
And also, what would I change if I want to modify the base chance to hit? (When AR = DR)
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
EDIT: Hang on, what am I meant to randomize to find out whether the attack hits or not? :L
GetRandomReal(1, 100) <= 100 * AR / sqrt(AR*AR + DR*DR)
If success, then hit.

And also, what would I change if I want to modify the base chance to hit? (When AR = DR)
That is troublesome with this equation. I could come up with another.
 
Level 8
Joined
Mar 3, 2009
Messages
327
I'll need to test it tomorrow to decide what percentage i need. But if you could come up with either a 50-60% chance one, or a more malleable formula, that would be nice of you :)

EDIT: dont worry about more formulas if you didnt start, it works great! thanks :D
 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,240
Ok, you can try this:

difference = ar-dr
if difference > 0 then
hitRate = baseChance + sqrt(abs(difference)) * plusMod
else
hitrate = baseChance + sqrt(abs(difference)) * minusMod

baseChance is the chance when ar=dr. PlusMod is by how strongly the chance increases when ar > dr. MinusMod is how strongly the chance decreases when ar < dr.

You'll see that this causes a "knee" when ar is around dr, and the ar gain there is very effective.

Values used
baseChance: 60
minusMod: 5
plusMod:4

Hit_chance_table_2.jpg
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Remember that evasion can be very stupid late game if you got a lot of health and damage reduction.

If you are level 100 with a ton of stats against a level 1, it will deal near insignificant damage to you (HP regen can counter it even if that is enabled). Adding an evasion system multiplys your effectiveness menaning you not only take proportionatly less damage out of total HP, but also reduce more damage via armor and evade most attacks. This is a product of 3 factors which gives and unnescescary uberness against early game badies at high levels which ultimatly can be looked as a design flaw outside of linear games where you will always fight badies with increasing stats to match.

So what do I advise? Well use evasion sparingly. A huge monster like a gient granite golem or wendigo are hardly going to be able to evade atacks, even if they come at a snail rate towards them. Small monsters like a murlock or killer rabbit (lol) would be hard to hit with slow attacks as they could easilly move out the way.

Thus you could have a crule but unique agility cutoff system. Monsters than can evade require a minimum amount of agility to even be able to hit, a stright line cutoff to hit them that drops from a evasion strength down to near 0 (5% probably is a good amount if you think 0 is too cruel). Any Agility after the required will steadilly bring up the evasion chance until a maximum is reached (after which agility no longer increases hit chance). The better the evasion magnitude, the higher the requirements to be able to hit (the cuttoff) and the lower the maximum cutoff.

Examples....
No evasion (eg a building), always 100% chance of hitting.
Light evasion (eg a footman), capped at 100% with cutoff at 80%.
Medim evasion (eg a bandit), capped at 95% with cutoff at 60%.
High evasion (eg a ninja), capped at 90% with cutoff at 40%.

The cutoff is a product of agility againt level. For example against medium it could be twice agility has to be greater than the enemy level while on high it must be a tenths of your agility must be higher than the enemy level. The amount of agility past the cutoff to hit maximum could be the same between all evasion types (like 100 agility).

The advantage of such a system is it creates an annoying (in a good way) bady neiche. The high evasion badies can only be hit by heroes with insane amount of agility and as such you need one to do well. Low agility heroes like a strength hero could have high physical damage yet would never be able to kill high evasion badies. The low and medium evasions classify the amount of agility one needs to actually be able to fight well while the high requirement to max hit chance means that strength related heroes will still get their damage reduced by continious misses.

The only flaw with this system is that you must be careful to greatly weakon agility heroes so they need strength support (like low health or less damage) otherwise you will fall into the trap of agility heroes being too strong.
 
Level 13
Joined
May 11, 2008
Messages
1,198
dr super good i think you posted a huge post for nothing. you seemed to misunderstand what original poster is doing.

there are plenty of maps where there are not str, agi and int heroes. for example, in my tdht map, all the heroes are int heroes.

i don't think he's using blizzard's evasion ability and i don't think he's using agility heroes.
 
Level 8
Joined
Mar 3, 2009
Messages
327
Thanks super good, and yes I understand. I have a kind of backstab system, where attacks from behind always hit for 2x damage, and spells will always hit. Taking on big baddies early game forces some team play, and there will also be mercenaries available eventually maybe so I will be sure to keep it balanced. The bosses needed to be tougher anyway.

I appreciate the concern :)

EDIT: Also, the reason i implemented this was to ensure some agility and strength being shared among non-agility heros, it was kind of underpowered.
 
Status
Not open for further replies.
Top