What is delta time?

I have already did a post on this but it didn’t help much. So all I want is to know what is delta time. How it works and an example.
It would be helpful if anyone can help me on this.

There is already a great tutorial by Halalaluyafail3. Google before asking already answered questions.

Read the above, narrow down your question, and reword it so people can actually give you an answer.

Delta (d) simply means change in, i.e. dt = change in time. In calculus dx and dy are the changes in x and the changes in y. You need a start point and an end point to record the change in time. So imagine you turn the kettle on at 11:00am and it finishes boiling at 11:01am then dt is equal to 1 minute. You can use the changes in time to make sure certain events happen at a consistent rate.

So imagine the kettle boiling is happening on my computer and on your computer, it takes 1 minute on yours but say it only takes 50 seconds on mine (10 seconds quicker). You can use the difference in both our dt’s to add 10 seconds to my computer to make sure the kettle boils at exactly the same time for us both.

1 Like

I don’t know if I’m too dumb but this post haven’t helped me. I already checked this post 1 week ago

The reason the time it takes for the kettle to boil on my computer may differ to the time on yours is down to ping, internet speed, CPU power, etc… So to make sure events are in sync for everyone, regardless of the device they are using you measure the time between the start of something and the end of something, on both computers, and offset the time difference (dt) between them to make sure it remains in sync.

1 Like

Delta time is the interval in seconds from the last frame to the current one or The time (in seconds) that has elapsed since the previous frame

I personally use it for lerping like in this script for example

local runService = game:GetService("RunService")
local speed = 8
local goal = Vector3.new(0,10,0)
local part = script.Parent

wait(4)

runService.Heartbeat:Connect(function(deltaTime)
   part.Position = part.Position:Lerp(goal, deltaTime * speed) 
   wait()
end)

That is interesting but can u give any application on how it works in luau

Another example could be health regen!

local regenAmount = 5 -- every second, they get this much hp
local humanoid = humanoid --pretend this is set.
local runservice = game:GetService("RunService")

runservice.Heartbeat:Connect(function(dt)
   if Humanoid.Health < Humanoid.MaxHealth then
      Humanoid.Health += dt * regenAmount 
   end
end)

This works but I would tweak it a bit since this would be running forever lol.

But the example still stands, every full second they get 5 HP. Even if the game lags, the dt will still end up giving them exactly the amount of HP they need. For example if heartbeat lags for two full seconds, the dt would be around 2. Since 2 * 5 is 10 then it would give them 10 HP.

3 Likes

Ok what happens if we don’t put dt