Okay, I know this isn't sci so I don't know how many math experts hang around these parts, but I need some help. Bare with me, I have diagnosis-able brain problems when it comes to math stuff, so I'm a bit stumped here.
I have this shitty game thing I'm working on and I need to figure out how to process an effect that scales with the stat it effects over time.
So lets say x is health or something, like 100 hp and the effect adds 25% of x to x each minute. I want to pass 3 minutes or something
This works fine if I interval the equation each minute that passes, like below
given that x = 100
1: x += (x *0.25) = 125
2: 125 += (125*0.25) = 156.25
3: 156.25 += 156.25*0.25 = 195.312
So there's that, but I don't want to interval through each minute of time that's passed. say its 1440 minutes or something, I don't want it to cycle each time, I want a single equation but how do I write it so it just scales for a time variable
obviously if t = 3 and x = 100
x += (x*0.25)* (t) = 175
and that's not the same outcome as doing the equation 3 times, so my math-dead brain is stuck
>>156241
Sounds like compounding interest.
x = P(1+(r/n))^nt
P = initial amount = 100
r = interest rate = .25 (25%)
t = total time = 1440 minutes
n = compounds every t = 1 since you want it every minute
>>156253
With everything plugged in we get:
x = 100(1.25)^t
>>156263
I'm not sure how you achieved that, but it worked fine for me.
>>156266
oh, huh
I did this
N = 100;
T = 3;
N = (N*(1+(0.25/1)))^T;
Whats that "for x in range(4)" part mean? Sorry for my ignorance, I'm pretty new to code math
>>156274
It was just a way for me to test for x = {0,1,2,3} in my equation (In this case, x was time).
In your equation you're raising everything by t, but only the (1 + .25/1) needs to be raised by t.
>>156274
Oh well that's one thing, but I also realized ^ was a short cut for a binary xor operator, not exponential. Had to use "Math.Pow()"
Works fantastically now. Thanks a lot anon.
>>156280
Glad it worked out.