Calculating shot hit percentage based on tile distance

Started by
9 comments, last by Rich76 6 years, 4 months ago

With permission to remake a game, I'm trying to figure out its shot hit percentage formula, or at least be close. Everything I try is terrible. Any ideas?

The max tile range is 23, and the expected result should be as close to the following as possible:

Tile Distance    Hit%
23    1.05%
22    1.2%
21    1.38%
20    1.6%
19    1.86%
18    2.19%
17    2.6%
16    3.12%
15    3.79%
14    4.66%
13    5.82%
12    7.4%
11    9.61%
10    12.8%
9    17.55%
8    25%
7    37.31%
6    59.25%
5    100%
4    100%
3    100%
2    100%
1    100%
0    100%

 

EDIT: To explain better, the game is a 2D tile game. The character will fire at the enemy from a tile range between 0 and 23.

Advertisement

A quick and dirty solution just plotting some data points and curve-fitting:


if (tileDistance < 6)
  return 100.0;

return (64.81704965 / (tileDistance - 5.061304447));

Not exact, but fairly close.

Hello to all my stalkers.

Thank you! You're much closer than I.

That said, why not just use an array and index into it, getting the exact values?

Hello to all my stalkers.

6 minutes ago, Lactose said:

That said, why not just use an array and index into it, getting the exact values?

I don't know. I was debating whether or not I wanted to hard-code the figures in. I was just hoping I could find a quick and easy formula which would allow me to easily make changes. For example, increase tile range, or slightly tweak the numbers later, if I wanted to.

I plotted the numbers, and it produces a smooth curve.

plots.gif


min(100.0, 12800.0 / (x*x*x))

 

1 hour ago, alvaro said:


min(100.0, 12800.0 / (x*x*x))

 

^ Holy!!! I have no idea how you figured that out but I'm absolutely amazed. Thank you!

22 minutes ago, Rich76 said:

^ Holy!!! I have no idea how you figured that out but I'm absolutely amazed. Thank you!

In order to see how quickly the value decreases with distance, I divided the value at 10 by the value at 20, and their ratio was exactly 8. So if a factor of 2 increase in distance results in a factor of 8 reduction in the value, it suggests a dependence with 1/(x*x*x). 12800.0 came from fitting a single point at distance 10. Then I saw all the other points match exactly.

5 hours ago, alvaro said:

In order to see how quickly the value decreases with distance, I divided the value at 10 by the value at 20, and their ratio was exactly 8. So if a factor of 2 increase in distance results in a factor of 8 reduction in the value, it suggests a dependence with 1/(x*x*x). 12800.0 came from fitting a single point at distance 10. Then I saw all the other points match exactly.

Thank you! I was able to figure out 2 more game formulas doing this.

This topic is closed to new replies.

Advertisement