The following is what I am hoping to accomplish:

enter image description here

The main points here are:

  • It curves
  • It can't ever reach $1$
  • Any number can be supplied for $X$
  • The resulting $Y$ gets the most 'bang for its buck' earlier on the $X$
  • $Y$ past a certain point (lets say around $1$ on the $X$) goes up really really slowly

I'm a game developer, and I need this so that the higher a supplied X goes, it never hits $1$ on the $Y$, but there is at least a little room for growth early on (between like $0.01$ and $0.5$ish on the X). Think of like 'run speed' of your character... there is a real limit on how fast a character should feasibly be able to run, but if someone were to level up their ability to run really high, there should be diminishing returns that total under the fastest the game should ever allow, but still allowing for growth (for instance, if $X$ is $10$, it should be extremely close to $1$ on the $Y$, but it still should be lower on the $Y$, than $20$ on the $X$).

Thanks in advance for all of your help! I don't have any better place to ask this, so your help is very very appreciated!

  • 1
    $\begingroup$ please help me understand, is the speed of the character just based on level? $\endgroup$ – Saketh Malyala Jun 15 '17 at 1:17
  • $\begingroup$ All of the answers helped me more than I could ever state. Thank you all for your help! <333333 $\endgroup$ – return true Jun 15 '17 at 1:42
  • $\begingroup$ It is asymptotic to 1. $\endgroup$ – Daniel R Hicks Jun 16 '17 at 12:29

Consider a graph of the form $\displaystyle f(x)=1-e^{-kx}$.

Let $k$ be positive.

Let's say there's a point at which the growth slows down past a certain point, $a$.

The larger $k$ is, the smaller $a$ is.

So I'm curious, because this will help me answer your question more accurately and thoroughly, what is this graph representing?

Is it saying that the character accelerates as they run, but doesn't go faster than $1$ m/s? Because that's what I understand.

Or maybe, is it saying that as you level up your character, they run faster and faster? But even at higher levels, they will not run $1$ m/s, although they get closer?

  • $\begingroup$ many thanks, I have read that equation before, but maths isn't my native language. Could you explain what f, e, k, and z are? Many thanks in advance, I think your answer is correct and I have read that around the internet,... but I just can't make sense of what it means. Thanks again! $\endgroup$ – return true Jun 15 '17 at 1:11
  • $\begingroup$ $x$ is the variable. $e$ is a constant = 2.718... you can swap out $e$ for any positive number ABOVE $1$, if needed. $k$ because that is the rate of decay. notice decay in the sense, the difference between the speed and 1 is shrinking $\endgroup$ – Saketh Malyala Jun 15 '17 at 1:14
  • 12
    $\begingroup$ Because $e^{-kx}$ is equal to $(e^{-k})^x$, this can be written in the simpler form of just $1 - b^x$ where $0 < b < 1$ $\endgroup$ – Ben Voigt Jun 15 '17 at 3:41
  • 5
    $\begingroup$ Or maybe 1 is $c$. And OP is using Natural Units in a space-related game. :D $\endgroup$ – muru Jun 15 '17 at 6:32
  • 10
    $\begingroup$ In most programming languages, the natural way to write $e^{-kx}$ is exp(-k*x). $\endgroup$ – Anton Sherwood Jun 15 '17 at 8:51

A few possibilities, depending on what you have available:

  • $ 1-e^{-kx} $ for ($k>0$) will be the first one any mathematician will recommend.
  • If you don't have $\exp$, $1-2^{-kx}$ (again, $k>0$) is probably easier to implement depending on what units you're working with.
  • $\frac{2}{\pi}\arctan{x}$.
  • On the more complicated side, $\tanh{x}$.

The latter two have the advantage of having similar behaviour for negative values since they are odd functions.

  • 1
    $\begingroup$ $1-2^{kx}$ requires negative $k$, then? $\endgroup$ – hBy2Py Jun 15 '17 at 17:36
  • 2
    $\begingroup$ For your first bullet point, you want $k>0$, or remove the sign from the exponent. $\endgroup$ – Mad Jack Jun 15 '17 at 18:39

You can try a Hill function. The function $$ f: x \mapsto \frac{x}{x+h} $$ has the following properties:

  • $f(0)=0$;
  • $f$ is increasing;
  • $\lim_{x \to \infty} f(x) = 1$, so $f$ approaches $1$ as $x$ grows large;
  • $f(h) = \frac12$, so by choosing the $h$ parameter one can control at which value of $x$ the function takes half its maximal value.

Example for $h=1$ (blue), $h=2$ (orange) and $h=10$ (green):

enter image description here

To get functions with a different shape, you can experiment with functions of the form $x \mapsto \frac{x^n}{x^n+h^n}$, where $n$ is a second parameter. These functions also have the four properties listed above.

  • 3
    $\begingroup$ The nice thing about this function is that it's much faster than exponentiation. Further tuning of the shape could use lower order terms like $\frac{x^2 + ax}{x^2 + 2a(x+h) + b(x-h) + h^2}$. $\endgroup$ – maaartinus Jun 15 '17 at 20:40
  • $\begingroup$ @maaartinus: Generally one calls those higher-order terms rather than lower-order, where "order" refers to the complexity (degree). The basic form is the 0th-order or 1st-order, and the refinements are higher-order. $\endgroup$ – user21820 Jun 16 '17 at 7:38
  • $\begingroup$ Yes, I also thought about a rational function like $f(x)=\frac{x}{x+h}$ for $x\ge 0$. Note that $\frac{x}{x+h} = 1 - \frac{h}{x+h}$ which shows how far the quantity is from reaching one (its horizontal asymptote). The graph is a piece (an arc) of a hyperbola. $\endgroup$ – Jeppe Stig Nielsen Jun 16 '17 at 11:28

One such solution is

$$ f(x) = 1 - e^{-2x} $$


Advantage to @Saketh Malyala for providing the answer first.
A family of curves: $$ f(x) = 1 - e^{-kx} $$ corrected

  • $\begingroup$ Second image is wrong, larger the k more steep towards the y axis. $\endgroup$ – Fredrick Gauss May 15 '20 at 21:36
  • 1
    $\begingroup$ @Fredrick Gauss: Image corrected. My error was in creating the tags for the legend. Thanks for reporting this. $\endgroup$ – dantopa May 15 '20 at 22:06

The logistic function $$ f(x)=\frac{1}{(1+e^{-x})^{\alpha}} $$ for any $\alpha>0$ has the desired properties as well. Below is the graph of the function when $\alpha=1$. The wikipedia article on sigmoid functions has more examples of functions which have a similar shape and the desired properties. logistic


If you wanted to, another way to approach it is from a statistical standpoint. What I mean by that is this graph looks very similar to that of a cumulative geometric distribution graph found mostly in statistics. This distribution would be created through a simple question of how many tries it takes to accomplish a task. So 1=y denotes a 100% chance that by that try it will accomplish the goal. This is similar to a binomial distribution differing only in that in a binomial 100% is achievable once all trials are conducted, but with a geometric distribution you have an infinite number of trials. This means that a distribution with probability p of success has the equation for success on the first try $= p$, the second try = $p+p(1-P)$ the third try being = $p+p(1-p)+p(1-P)^2$ and so on until you approach 1 but never actually hit $1$. $p$ in this distribution is a probability of success on any given independent trial so it must be below $1$. To give an easy example of this in action imagine a game where you win when you flip a tails on a coin. The probability of success on any independent trial is $0.5=p$. This means the first flip has a $.5$ chance of success. The chance that you win BY the second try is $.5$ from the first try and $.25$ the second time calculated by $.5(1-.5)$ added together to make a total probability of $.75$. Success BY the third trial is $.5$ from the first added to $.25$ from the second and then $.125$ from the third calculated by $.5(1-.5)^2$ added all together for a total of $.875$ continue this on and eventually you will approach $1$ but never actually hit it. In Texas Instruments ti84 code this distribution is geometcdf(p,x). Hope this helps, if nothing else just another option in case the formulas above don't work for you.


As I have not seen this function mentioned in the other answers, I think $$1-(1+x)^k,k<0$$ At $x=0$, this function will be zero for all values of $k$. This function will definitely "curve", it increases indefinitely yet never goes above one, and it works for all $x\geq0$.

The closer $k$ is to zero, the slower the function increases.

  • $\begingroup$ The special case $k=-1$ gives $1-\frac{1}{1+x}=\frac{x}{1+x}$ which is a member of the family user133281 suggests in his answer ($\frac{x}{x+h}$). For other negative $k$ your example is not covered by the other answer. $\endgroup$ – Jeppe Stig Nielsen Jun 16 '17 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.