Simple math problem :)

Started by
9 comments, last by pinczerek 22 years ago
Hi and hello! I''m new here so excuse me for any strange questions. Thanks. Anyway, I''m doing a simple wargame and I need a math function that tells me what is the chance of hitting one unit by another with firearm. This function should return a percentage value depending on a distance between units. I know it can''t be a simple linear function but I don''t have any idea how to find a proper one. Would any of you help me please? Thank you!
Advertisement
Create an armor value for every unit. Create a tohit value for every weapon/unit. Extract the armor from the tohit and create a random number. If the random number is higher then its a hit.


Thanks Black_Star but you didn''t get what the problem is. All I want is a math formula which tells how much the hit percentage decreases with the distance between units. I cannot use a simple linear one because for example a chance of hitting a target 4yards away is not 2 times smaller than hitting the same target but 2yards away... I hope now it''s clear

exponential? something sine based perhaps?

A using the -infinity to 0 section of the 1/x based graph looks like the right kind of shape if you translate it a bit into +itive values..

Or you could just build a look up table beforehand and linearly interpolate between values at runtime (or do this anyway if you come up with something complicated to calculate).
Try using the gravitational force of attraction between two bodies equation and modify it for the probability of a hit. The equation has a distance^2 in the denominator which is applicable in your case.

Amresh
ramresh@dsqsoft.com
dArkteMplaR of Delphi
h = chance to hit
d = distance to target (in meters or tiles or whatever)
r = range of unit (in same units as above) r is the distance at which the unit no longer has a chance to hit the target

r > 0
d <= r

h = 200 * (r-d)*(r-d) / (r * r)

this gives a bonus to hit ( h > 100) when d <= 1/4 r
works well when there is armor offsetting the chance to hit, i.e. at close range you have a better chance to find the "chinks" in the armor. or you can cap h at 100% or as many games do, 95%


cheers,
-mat


mat williams
Lead Programmer, Designer
Zero Sum Software
www.zero-sum.com
mat williamsLead Programmer, DesignerZero Sum Softwarewww.zero-sum.com
Thanks Thathmew!!! That''s the golden formula I was looking for! It produces great numbers and is simple enough to make some changes to it... Big kisses! Just kidding...

Best of luck to you all

I don''t like queerish canadians.
And what about even more queerish Poles? C''mon, you''ve got to love us. Let''s have a shot of vodka my dear anonymous friend...

I don''t like Anonymous Posters.

This topic is closed to new replies.

Advertisement