I am working on an american football game and where I am trying to decide who wins the battle between a ball carrier and a tackler. If the ball carrier wins, he breaks the tackle, if the defender wins he tackles the player.
Right now I’d like to based the decision primarily on the ball carriers “Break Tackle” ability and the defenders “Tackle” ability. Both are from 1-100. So the defender may have a 80 tackle ability and the ball carrier may have a 60 break tackle ability.
Of course I could just compare the two and make a decision on the greater number, but I am hoping to add some randomness as well as reality to the outcome. I could come up with my own crazy wighted method, but am pretty sure it’s going to get a little hacky, so I was hoping to do it the “right” way. Or at least a better way.
I am looking for any thoughts or references people may have regarding theory behind these kinds of decisions.
In a situation like this i would compare the two variables and use the result to weight a random number which determines the outcome. This means that the bigger the difference between the values, the more likely the outcome will favour the higher ability, but still leaves some randomness in there to make it more realistic.
ie
int r = breakTackleAbility - tackleAbility;
int outcome = Random.Range(0,100) + r;
if (outcome < 50) tackleSuccessful = true;
else tackleSuccessful = false;
Then you just need to decide how you want it to behave in your game and adjust accordingly. For example, in the above, if the breakTackle ability is 50 or more higher then the tackle ability, the tackle will be broken 100% of the time. You can put a multiplier on r to make this threshold higher or lower.
Thanks Arghonaut. I feel pretty comfortable with that solution and will give it a try.
float breaktackle = breakTackleAbility / ( breakTackleAbility + tackleAbility ); // assuming all values are floats, otherwise cast them
or other way round:
float tackle = tackleAbility / ( breakTackleAbility + tackleAbility );
this gives you a nice value between 0 and 1 which you can compare directly towards Random.value to decide wether it happens or not.
example for breakttackle:
breakTackleAbility = 1; tackleAbility = 99; breacktackle = 0.01,
bool tacklesuccessfull = breacktackle > Random.value; // will be true for only 1 % of the cases representing the "strength" ratios of both abilities