How do I use dt?

1 favourites
  • 10 posts
  • I feel like I've gone down this rabbit hole many times and for the life of me I can't figure out the "accurate" formula for using dt.

    In some examples, I've seen it presented as "self.x - 20*dt". And in other examples, I've seen it as "self.x 20(dt/60)" (or something like that. And others have mentioned you need to consider your own refresh rate when you're programming, and not bother with 60.

    Can anybody explain like I'm five, how to transition between "move X amount of pixels per tick" to properly using dt for movement/animation. Because no matter how much I read documentation, scour the forums, and look at the examples (even the Kiwi example uses dt in different ways). I just can't wrap my head around it, and literally have become paralyzed by this and feel like I can't move forward with my projects until I make sure they're frame-independent.

    Tagged:

  • What is anything times 0?

    Think about dt being zero.

    Then think about dt when its not.

  • Sorry newt, that doesn't really help me. ):

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • dt is the time since the last tick.

    So at 60 fps dt is around 16 ms.

    If your framerate drops so does dt.

    If your framerate goes to zero so does dt.

    If your frame rate is halved so is dt.

    Anything times zero = 0

    So if your speed, a value you come up with(in pixels per second), say 60 is multiplied by dt and dt= 0 then the speed will be zero.

    If dt was 0.16 then your speed would be 0.96 pixels per tick, 60 pixels per second in this case.

    To test set a sprite's x to self.x+(speed*dt)

  • Nice explanation bro, now in know about dt. Thanx

  • Just in case you ever want to use lerp in your game, it uses a slightly different formula with deltatime.

    construct.net/en/blogs/ashleys-blog-2/using-lerp-delta-time-924

  • Dt is just used for things to change at the same rate no matter the framerate.

    Most common use is for something you want to smoothly move 100 pixels per second.

    set x to self.x+100*dt. Basically rate*time=distance.

    Sometimes the formula can be written dt/60, but that can be rewritten to 1/60*dt.

    There are other ways people use dt in formulas with varying complexity. You'd have to look at those formulas case by case.

  • Just don't divide by dt.

  • Thank you guys for the help, I think it's starting to come together for me.

    On the other hand, all behaviors already account for dt, right? So if I move my player 100 pixels to the right every tick using the Simulate 8Direction action, I don't need to account for dt?

  • Correct all the behaviors should have dt included.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)