Archived

This topic is now archived and is closed to further replies.

Simple math problem :)

This topic is 5742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites