0
$\begingroup$

Please excuse me because I don't have a strong grasp of mathematical notation, I'm a programmer and understand code best.

I have a variable called momentum, which is tending towards 0 like this:

momentum = momentum * 0.9

This repeats every frame. But the trouble is that the time of each frame is variable. How can i make sure that the rate of deceleration is consistent even as delta time changes?

  • 0
    In other words, you effectively want momentum to be a function of frame instead of a function of time. I think that's more of a programming question than a math one.2011-08-02
  • 0
    This question belongs at programmers.SE. I agree with @anon. http://programmers.stackexchange.com/2011-08-02
  • 0
    No it's still going to be a function of time, but i need to factor delta time in there somewhere to make it work.2011-08-02

1 Answers 1

1

How about momentum=momentum*0.9^(delta time), where delta time is the time since the last frame? It should be measured in units such that you want the momentum to decrease 10% in one unit of time.

  • 0
    This is exactly what i needed. Just tested it and it works. Thank you.2011-08-02
  • 0
    Glad to hear it. You could accept the answer by clicking the check mark (or wait a few days to see if you get a better one and accept that) so the robot doesn't keep bringing the question back.2011-08-02
  • 0
    After further testing I find that this gives me pretty close results, but not precise. I have no way of knowing if this is to do with the maths, or if its to do with inaccuracies elsewhere in the system.2011-08-02
  • 0
    It is just using the properties of exponents. $0.9^{t_1+t_2}=0.9^{t_1}0.9^{t_2}$. If you find the results are not precise, you could identify the behavior and maybe I can help.2011-08-02