Problem description: I want to program a chance of hitting based on speed. I need it for my game. So if both the attacker and defender have equal speed then the attacker has as much chance of hitting the defender as the defender dodging the attack. If the attacker has greater speed then he has a higher chance of succeeding an attack, if the attacker has a lower speed than the defender then he has a lesser chance of hitting the defender.
|
Dec 26 2013, 1:57 pm
|
|
Perhaps use ratios?
|
what about this:
mob/verb/test_spd() |
I suppose it works.
spd1 has a 60% chance of being 5 or higher. spd2 has a 20% chance of being 5 |
It's a little similar. It just considers the ratios of the speeds. Your base attack chance is 50%, that's why attackChance has 50 built in. The end part is the ratio of the speeds. If the attacker has a higher speed, then it multiplies 50 by a number greater than 1 (because X/Y > 1 where X > Y). Which ups the attack chance. So, for example.
Attacker_Speed = 10 |
I would use a sigmoid sort of function.
These generally take one to three parameters. For our case, I think three is most appropriate. I'm going to call them attackerSpeed, defenderSpeed, and scale. The code for it looks like this. proc/hitChanceSigmoid(attackerSpeed, defenderSpeed, scale = 10) When the difference between the attackerSpeed and defenderSpeed is equal to scale, then the chance to hit is roughly 91%. If the difference between the speeds is equal to 1/2 scale, then the chance to hit is roughly 75%. If the two speeds are equal, the chance to hit is 50%. So you adjust the value of scale to match what is most appropriate for your game. For example: In an RPG, if you gain 1 speed per level and you want someone level 30 to hit someone level 20 about 90% of the time, then you can use a scale of 10. If you want someone level 50 to hit someone level 20 only 75% of the time, then maybe you should adjust scale to be 60. This should make designing how the dodge mechanic scales relatively straightforward. This sigmoid function has two horizontal asymptotes: One at 100%, and one at 0%. This means that you will never get a chance to hit that is below 0% or above 100% The problem with Lugia's approach is that it can yield a chance to hit that is not confined to 0% to 100%. For example, if attackerSpeed were 5, and defenderSpeed were 2, you would get a chance to hit of 125% If you reverse them, with the attackerSpeed of 2 and defenderSpeed of 5, then you would get a chance to hit of 20%. Using my sigmoid function for speeds of 2 and 5, you would get a chance to hit of 33% one way and 67% the other way. |