# Calculating shot hit percentage based on tile distance

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

## Recommended Posts

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.

Edited by Rich76

##### Share on other sites

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.

##### Share on other sites

Thank you! You're much closer than I.

##### Share on other sites

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

##### Share on other sites
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.

Edited by Rich76

##### Share on other sites

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

##### Share on other sites
min(100.0, 12800.0 / (x*x*x))

Edited by alvaro

##### Share on other sites
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!

##### Share on other sites
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.

##### Share on other sites
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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 31
• 16
• 11
• 10
• 11
• ### Forum Statistics

• Total Topics
634113
• Total Posts
3015592
×