Calculating an increasing exponent to some value (programming task to implement a poison in a game)

MOrlando616

New member
Joined
Mar 29, 2019
Messages
7
The title is probably grossly misleading. I have a programming task to implement a poison in a game. The poison will deal some amount of damage (say 200 damage) over some amount of time (say 15 seconds). It will deal damage every tick (say a tick is every 1 second, so 15 ticks of damage that will total the full 200).

The tricky part is, I want the damage to start off low and increase in severity as the poison reaches its full duration. To be linear, I can simply divide my total damage by the number of ticks, and that'll be how much damage each tick will deal. Another problem, however, is that the duration and damage can be upgraded, and so a tick may not cleanly fall onto the duration (maybe some damage left over, which I can just add to the last tick to compensate if that makes sense).

So x damage over y seconds, dealing damage on each tick (which is every z seconds)...but starting at a small value, like 2, and increasing until the last tick is something like half the damage (or 100). These numbers are arbitrary, I haven't done any balancing yet, but I can't wrap my head around calculating a curve for the values. Do I use log? Some exponential thing? I have no idea!

As an example: 200 damage over 10 seconds with a 1 second tick.
2, 4, 6, 10, 14, 18, 24, 30, 40, 52 (These values I just came up with by hand, but that helps convey what I want).

Thanks in advance!!
-Matt
 
Last edited:
I would look first at the sum:

[MATH]S=\sum_{k=1}^n a^k=\frac{a\left(a^n-1\right)}{a-1}[/MATH]
So, with \(n=10\) and \(S=200\) we'd have:

[MATH]\frac{a\left(a^{10}-1\right)}{a-1}=200\implies a\approx1.5299670675524091874[/MATH]
Thus, we'd have:

fmh_0034.png

This would at least give me a place to begin. :)
 
Last edited:
Wow ok, I think that makes sense, thank you! I'm going to simplify it a bit for myself, and just always have the number of ticks be some constant value, and I'll adjust the tick time accordingly (the rules are flexible so that won't be an issue). Let me get this into the code when I can and see how it works out.

Thanks again!
 
Oh man, it's been far too many years I think...how would I break down that formula to solve for a?
 
Oh man, it's been far too many years I think...how would I break down that formula to solve for a?

In general, you can't explicitly solve for \(a\); you'd have to use a numeric root finding technique. If you are going to have a relatively small number of tick/damage combinations, you could simply define constants to store the resulting values of \(a\) for those combinations. You could use W|A to find \(a\) for those cases. Here's how I found \(a\) for 200 damage in 10 ticks:


But, if you need to be able to find \(a\) for a large number of possible combinations that you can't necessarily predict at the outset, then you'll want to use a numeric technique.

Depending on the programming language you're using, there may be intrinsic functions, perhaps in a math library, that will do exactly what you need.
 
Ah ok, well that's not a problem. The way I've designed it, I can store that a value along with the damage value per upgrade level. Thanks again for the help!
 
If I were going to do this in javascript, I would use something like this

Code:
var a =[1.5299670675524091874], n, damage, health;

for (n = 1; n < 11; n++)
{
    damage = Math.pow(a[0], n);
    health -= damage;

    if (health <= 0)
    {
        //you're dead
    }
}
 
Yup, that's how I'll be handling it. It's in C# but it's basically the same thing. I'll just be taking my a coefficient and raising it to the number of the current tick.
 
Yup, that's how I'll be handling it. It's in C# but it's basically the same thing. I'll just be taking my a coefficient and raising it to the number of the current tick.

Sounds good...I wish you the best with your coding project. :)
 
Top