How do I get a stable deltatime?

Not favoritedFavorited Favorited 0 favourites
  • 13 posts
From the Asset Store
Empire Game has everything you need to create immersive, historical-turn-based games!
  • is it possible to somehow stabilize dt? How do you deal with this? In my project it is very noticeable, as it requires high precision. And in "loops" where dt is used, objects shake. I tried to set the dt to a variable. But in this case it will not change when fps changes.

    youtu.be/YwMu_JnUIr0

    Subscribe to Construct videos now

    Tagged:

  • Dt is just the time from the previous frame and should be approximately 1/screenRefreshRate. Although construct has settings to clamp that value

    You can improve things if you’re dropping frames. For example since it appears you have a 120hz screen then dt would be 1/120. if most frames are ~1/120 but some are 2/120. That means you should try to reduce the cpu/gpu usage to avoid dropping frames.

    However if frames aren’t being skipped we have no control over that small variation.

    If you want stable values you could use a fixed value instead of dt. Ideally 1/refreshRate but there is no direct way to access the refresh rate. Construct provides fps and ticksPerSecond i think. You could let the game run a bit and say, when time=1 then set a step variable to 1/ticksPerSecond. Alternately you could just average the value of dt from 100 frames and use that instead.

  • Thank you very much for your response! The issue is not that I’m afraid of FPS drops. Even in very simple projects, delta time is extremely unstable. I tried averaging values using an array, with both 100 and 300 values, but the result was still unsatisfactory.

    So far, I have found this method: dividing time by tickCount. It seems much more stable. I tested it on different monitors with different refresh rates. However, I’m not sure how resource-intensive this process is.

    What do you think?

    Subscribe to Construct videos now
  • So far, I have found this method: dividing time by tickCount. It seems much more stable.

    For what purpose? Where do you use this value?

  • > So far, I have found this method: dividing time by tickCount. It seems much more stable.

    For what purpose? Where do you use this value?

    I use delta time in loops to determine the movement trajectory. The loop runs until the object collides with an obstacle.

    As you can see, the red ball is shaking. This happens because delta time is used for its positioning.

    Subscribe to Construct videos now
  • Can you show your code, or share the project file?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • A question : is the red circle position calculated from the curve? Or is the curve calculated from the red circle position?

  • A question : is the red circle position calculated from the curve? Or is the curve calculated from the red circle position?

    They are calculated separately..Independently of each other

  • In a loop to predict the path of an object I’d recommend using a fixed value instead of dt. Probably 1/60 would be fine. That would eliminate the shake completely.

    Ideally the object’s motion is framerate independent so the path would be the same no matter what fixed value you used. The only thing that would vary is when the collision is detected. Unless you’re doing some kind of calculation to find the time of collision.

  • To smoothen the dt you could store the last n delta times and average them.

    This could be done with an array, every tick push dt into the back of the array and if length is greater then n pop front.

    To get the smooth dt loop over the array and add each stored value together, then divide it by array.length.

    Interestingly there are engines like Godot that do delta time smoothing by default (can be disabled in the settings). Though their implementation is probably a bit better than what I am suggesting. This may be interesting for Scirra to consider adding to c3.

  • To smoothen the dt you could store the last n delta times and average them.

    ]

    I don't see much difference

    Subscribe to Construct videos now
  • im_pro_viz An average of dt would be the same as time/tickcount.

    I agree with R0J0hound - you don't need to use dt at all in your case.

  • mhm interesting doing this gives me a really stable averaged dt (only going up by 1 on the 6th decimal point from time to time), but my dt is already much more stable than what you are have to begin with:

    Though I agree with Reddog and Dop, just using a fixed step should be fine for this.

    using time/tickcount is interesting too, but it's averaging over the whole game session, which imo is too long as it may be bad if some levels run worse than others on some users machine

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