Unity 2D Games Developer Question: Download Questions PDF
Tell me why Time.deltaTime should be used to make things that depend on time operate correctly?
![Unity 2D Games Developer Interview Answer Unity 2D Games Developer Interview Question](https://globalguideline.com/public/images/interview/2.png)
Answer:
Real time applications, such as games, have a variable FPS. They sometimes run at 60FPS, or when suffering slowdowns, they will run on 40FPS or less.
If you want to change a value from A to B in 1.0 seconds you can’t simply increase A by B-A between two frames because frames can run fast or slow, so one frame can have different durations.
The way to correct this is to measure the time taken from frame X to X+1 and increment A, leveraging this change with the frame duration deltaTime by doing A += (B-A) * DeltaTime.
When the accumulated DeltaTime reaches 1.0 second, A will have assumed B value.
If you want to change a value from A to B in 1.0 seconds you can’t simply increase A by B-A between two frames because frames can run fast or slow, so one frame can have different durations.
The way to correct this is to measure the time taken from frame X to X+1 and increment A, leveraging this change with the frame duration deltaTime by doing A += (B-A) * DeltaTime.
When the accumulated DeltaTime reaches 1.0 second, A will have assumed B value.
Download Unity 2D Games Developer Interview Questions And Answers
PDF
Previous Question | Next Question |
Tell me what is fighting? | Basic Unity 2D Games Developer Job Interview Questions: |