# Closer to a number without hitting it

## Recommended Posts

rpiller    839
Hey, so not a big math guy here but was wondering how I would calculate the following scenario.

Let's say I have an RPG and I want armor reduction to max out at 50%. Each level I give the player a certain amount of points to spend in various stats, armor being one of them. I want each point they spend in armor to get them closer to the 50% max but never actually hit it. What would the formula be for that and what would my factors to adjust the jump in % per point be?

Thanks!

##### Share on other sites
CombatWombat    673
http://en.wikipedia.org/wiki/Asymptote
http://en.wikipedia.org/wiki/Diminishing_returns

I think these will get you on the right track.

##### Share on other sites
rpiller    839
Thanks, that lead me to http://lostsouls.org/grimoire_diminishing_returns which is a pretty cool site that explains this really well, and more geared toward games.

##### Share on other sites
Concentrate    181
How about using arctan(x), it has an asyptote at pi/2 so if you want to cap it off at 50, you can scale it,
[code]
f(x) = 50 * 2 / pi * arctan(x) ;
[/code]

But the problem with that is that it will converge fast, so you can further scale it like so:
[code]
f(x) = 50 * 2 / pi * arctan(x / RATE ) ; //higher the rate slower it converges to 50, lower the rate faster it converges.
[/code]

Here is a gaph.
[img]http://img833.imageshack.us/img833/2180/screenshot20110723at115.png[/img]

The following are the equations for the above colored graph.
f(x) = 50 * 2 / pi * atan(x / 1 ); //black
f(x) = 50 * 2 / pi * atan(x / 10 ) //red
f(x) = 50 * 2 / pi * atan(x / 20 ) //blue
f(x) = 50 * 2 / pi * atan(x / 40 ) //green
f(x) = 50 * 2 / pi * atan(x / 100 ) //orange

You can do something similar off that line.

You can see, for example looking at the blue graph, at level 30 your armor resistance will be a little above 30, and at level 50, it will be a little less than 40, and so on.

## Create an account

Register a new account