3
\$\begingroup\$

Is it possible, using delta in my update method to increase a game speed variable exponentially on cubic growth (the blue line below)

enter image description here

My maths isn't great so I'm not sure how the formula would be put into practice using a float gameSpeed and delta in an update method -(void) update:(ccTime)delta I think I would also need a value to control the speed of the growth too?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Probably the most robust way is to store a linearly-growing gameTime value that you can update by just adding the delta to it each frame, then set gameSpeed = someConstant * pow(gameTime, 3.0) each frame.

But if you want to be able to do something interesting like changing the power continuously in real time, you could use the derivative: if y = t^n (in your case n = 3) then dy = nt^(n-1) dt = ny^((n-1)/n) dt, so you'd implement an update method like

power = 3.0;   // Or whatever power you want; it could even change over time
gameSpeed += someConstant * delta * power * pow(gameSpeed, (power - 1.0) / power);

That should cause gameSpeed to grow approximately as time cubed, but you could also alter the power to increase or decrease the rate of acceleration (or make it slow down again, using a negative power).

\$\endgroup\$
2
  • \$\begingroup\$ Thank you, excellent answer. Could you explain what someConstant is for please. \$\endgroup\$
    – Lewis
    Jul 6, 2012 at 19:08
  • \$\begingroup\$ @Lewis someConstant is just a global constant factor you can tune to scale the overall rate of growth. \$\endgroup\$ Jul 6, 2012 at 19:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .