Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity time.deltatime meaning

Rendering and script execution takes time. It differs every frame.
If you want ~60 fps, you will not have stable fps - but differing amounts,
of time passing each frame. You could wait if you are too fast,
but you cannot skip rendering when you are slower than expected.

To handle different lenghts of frames, you get the "Time.deltaTime".
In Update it will tell you how many seconds have passed 
(usually a fraction like 0.00132) to finish the last frame.

If you now move an object from A to B by using this code:

object.transform.position += Vector3.forward * 0.05f;

It will move 0.05 Units per frame. After 100 frames it has moved 5 Units.

Some pcs may run this game at 60fps, others at 144 hz.
Plus the framerate is not constant.

So your object will take 1-5 seconds to move this distance.

But if you do this:

object.transform.position += Vector3.forward * 5f * Time.deltaTime;

it will move 5 units in 1 second. Independent of the framerate.
Because if you have 10000 fps the deltaTime will be very very small 
so it only moves a very tiny bit each frame.

Note: In FixedUpdate() its technically not 100% the same every frame,
but you should act like it's always 0.02f or whatever you set the physics
interval to. So independent from the framerate, 
the Time.deltaTime in FixedUpdate() will return the fixedDeltaTime
 
PREVIOUS NEXT
Tagged: #unity #meaning
ADD COMMENT
Topic
Name
5+6 =