What is DELTA TIME? (help me)

Hello Gdevelop! I got some questions. I’m making a physics based game, and I recently discovered that my game acts weird on my old crappy computer. I discovered that I needed to use delta time. But… I don’t know how to implement it into my physics based world. I mean, I want to make my whole game use delta time, so it acts normal on a high refresh monitor.

1 Like

also… i just went to the wiki. If im saying something or doing something wrong, just tell me. I just read the first 2 sentences, so I’m not a pro at delta time.

1 Like

The wiki explains it best, as well as other posts here, but I’ll give you my perspective on TimeDelta() that helped me understand it best. Think of TimeDelta() as a second. If I’m running an event every frame (no condition attached) and I want to subtract a players health by 10 every second, I would subtract 10*TimeDelta() from the player’s health for the action.

When you think about it this way, your events are running very fast, TimeDelta() is going to return a small number like 0.0166 (this number is the time since last frame, different for every computer). Since your events are running so fast (let’s say 60fps), your health will be decreased by 10*0.0166 = 0.166 every frame. Now if we add that up so every frame health is being decreased by 0.166, and your computer is running the game at 60 fps, then after 1 second, your health will have decreased by 10.

So 0.0166*60 = 0.996 (or 1 second), thus after 1 second (60 frames have gone by), if we add those frames up, the overall decrease would be: health - 10*1. I hope that makes sense.

Another example:


I’m subtracting 20 from my health every second.

I’m curious what you mean by using delta time in physics. As far as I’m aware, the physics engine should be accounting for this. It just sounds like you’re not using the physics actions if it’s causing weird behaviour.

Can you screen snip some of the events involving the physics actions and conditions?

In the mean time, some bed time reading:

Delta time is the time since the last game frame. Delta time can vary from frame to frame, as it can be affected by the processing speed and resources in use. On slower computers this time is usually longer than on faster computers, because there is a lower FPS and therefore larger gaps or times between game frames.

By using delta time, you are ensuring you have a consistent rate at which something is calculated regardless of the computer speed or FPS. So for example, instead of moving a fixed amount every game frame, you move the delta time fraction of the of the distance each game frame.


For example, say you want an object to move 180 pixels in a second. So you take the average FPS
(around 60), which means about 3 (180 \ 60) pixels per frame, and add an event to update the object’s position 3 pixels every game frame. And it seems to work on most computers.

Now, say the frame rate on an old computer (say a 286) really, really sucks and, for example, the first frame takes 1/2 a second, the next 1/4 of a second, and then 2 more of 1/8 of a second. Using the 3 pixels per frame model, the object has only moved 12 pixels, once every game frame.

But using delta time, you’d move the object delta time * 180 pixels each frame. So first frame is 1/2 * 180 (90 pixels), second is 1/4 * 180 (45 pixels) and then 1/8 * 180 twice (22.5 pixels each time). The total number of pixels moved is 90 + 45 + 22.5 + 22.5 = 180 pixels, each second. It will look a bit jumpy and jerky, but the number of pixels moved each second remains the same regardless of the speed of the system running the game.

I read what others wrote above
Let you give me approach
I believe in rule
You are idiot (referring to me)
So you need as stupid explanation as possible to understand something
Then any1 can understand it also

This post will take me idk let’s say 3 mins to write
I give you apple
I tell you that you have 3 mins to eat it
What if i take longer to write my post?
You finish eating while i will be writing this post
What if i finish it faster?
You will be still eating while post will be already done

And what if i tell you that you need to eat this apple in time it takes me to write this post? PostDelta so to speak

You eat one apple per ZeroX4 PostDelta()

Now imagine we go with frames not posts
Frames skip a lot faster than i make post that is why you either multiply TimeDelta or divide

So you are not checking in what time period something happened like 5 secs or 3 mins or 7 hours
You check or set something to happen in time it takes one frame to get to next frame

As simple as that

@MrMen , thanks, but if I’m honest, i don’t really know what im doing. But yes, I am using physics events.
I was curious, so I just set max FPS to 30, and it was acting weird. The jumps were way stronger, and faster, and the game just felt weird to play. I set the max back to 70, but im still confused. Maybe it’s just Gdevelop acting weird. I tried to simulate a low refresh monitor, but I don’t think I did it right.