Calculating shot hit percentage based on tile distance

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now