(3, 0, 0) Time.deltaTime

Shwetaketu Dighe
3 min readMay 9, 2021

Let’s talk time!

The very first ‘boss fight’ in this journey of learning game development in Unity has to be understanding Time.deltaTime. Let’s try to break it down how it’s calculated to better understand it.

Foremost, Time.deltaTime is a read-only value. This means you will never be able to set it, but only get the value to make our program frame-rate independent. Simply put, Time.deltaTime is the amount of time passed since the previous frame was rendered.

Conjure up this scenario, you have an object which you want to move along the z-axis at the speed of 10. Naturally, you would declare a variable for speed, set it’s value to 10 and change the object’s translation, like so;

Here, Unity keeps on updating the ‘Update’ method and keeps drawing the outcome of it. Imagine a loop. Although, the time taken between drawing these two frames is not constant. This time depends on your computer.

The problem:

Now, as we know some people have PC’s with better hardware resultantly getting a better FPS as an outcome. Even two PC’s with the exact same hardware have different FPS numbers depending on the number of applications that it might be running simultaneously. Now imagine your object’s speed getting multiplied by this constantly changing value.

Result: your object doesn’t always travel 10 units in one second, or worse, during each playthrough, your object travels at different speeds.

Solution:

Time.deltaTime to the rescue.

By simply multiplying this line of code with Time.deltaTime, our program updates the speed value by multiplying it with the amount of elapsed time since the previous frame update. Hence, our speed value is always multiplied with the same amount as that of the time passed since the previous update method was called, thus making it frame-rate independent.

To understand this in a much better way, look at this image I found online. Here, the deltaTime value would be 0.25 seconds

source: https://www.parallelcube.com/2017/10/25/why-do-we-need-to-use-delta-time/

and here the deltaTime value would be 0.5 seconds

source: https://www.parallelcube.com/2017/10/25/why-do-we-need-to-use-delta-time/

Note that even if your computer’s FPS drops or surges during a play session, be assured that the deltaTime would be automatically updated. This always ensures our objects travel at the speed at which we intend them to travel. This is what I mean by frame-rate independence

--

--