Understanding Time.deltaTime

In this course we have been introduced to the concept of Time.deltaTime . Now I have seen this plenty of times, and I thought I understood it, but now my mind is just a mess trying to understand what it is !

Would like someone to explain me what is it and why was used exactly in the player movement? What does it mean that it is “independent of the frame rate”? And how do I use it in the future when it is needed?

Hello Shahar,

Time.deltaTime is the time in seconds it took to complete the last frame.

Let’s say you have some code that detects for the pressing of a button to move a character in your Update method. You want to move the character on the X-axis 10m per second. Update is called once per frame, but on devices which render those frames either faster or slower than one frame per second, you will get varying results for the character’s movement. On very fast devices, a player may have an advantage by being able to move much more easily than a slower device. A slower device may have the character appear jittery and lose the smooth movement between frames, making a game unplayable.

As Update is called once per frame, you can multiply the movement value of 10 by Time.deltaTime, you would now be moving the character 10m per second rather than 10m per frame.

We could now say that your movement code is independent of the frame rate, it doesn’t matter if someone has a device capable of rendering the frames more quickly/slowly, as your rate of movement will be consistent on all devices.

I hope helps :slight_smile:


See also;

2 Likes

That made it all so much clearer, thank you so much !
I appericiate it :slight_smile:

1 Like

No problem, happy to help Shahar :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms