- Home /
Update() intervals and fps
Hello, i know that fixedUpdate() is called every 0.02 seconds and that update() calls are not consistent. FixedUpdate() is recommended to be used with physics calculations and update() for everything else, right?
The documentation states that update is called every frame. So if my fps are lets say 70 its called 70 times per second. If my fps are 200 its called 200 times per second. But wouldnt this result in a faster/slower game when my fps changes if calculations are done in update? Also if i want to track anything that is time dependent or detects inputs this would also be messed up. Like playing old games on emulator without capping framerate.
You can use Time.deltaTime if you want to be frame independent. And, tracking something that is time dependent can also be done by Time.deltaTime without messing anything up.
thanks for your answer aditya007. i want to clarify this with an example, to make sure that i understood that right: lets say i simply want to move my character with inputs (w,a,s,d) in Update().
if i just move my character with transform.Translate(movementvector) the movement would be different on different machines (fps dependent), right? ins$$anonymous$$d i should use transform.Translate(movementvector * Time.deltaTime)?
I have looked up this video about Time.deltaTime https://unity3d.com/de/learn/tutorials/topics/scripting/delta-time
For me this video is confusing because it looks like the slowdowns/speedups only occur in between a time interval but at the end of this time interval both squares are at the same position. Also the tutor says that Time.deltaTime is used to make the movement smooth here.
But wouldnt this then mean that Update() is already executing a set amount of times per second with the single frames being not consistent within this second? However the documentation states that its called every frame. What i mean is that the red square without Time.deltaTime should have moved a lot faster overall than the other one, if Update() is executed once per frame.
Im now more confused than before...
Edit: i managed to unlock my framerate so i was able to test this in the editor. for the movement i simply added my vector to transform.position. update() is called indeed every frame. high framerates (over 100) = extremely fast movement, low framerates = slow movement. Time.deltaTime fixed this. i think i just misunderstood the example with the squares in the video.
Yes you misunderstood the example in the video ^^. The first part of the video focuses on the tiny flucuations that the frame time might have and deltaTime "smoothes" those (at least visually). Your case, where you have different framerates, is handled at the end of the video where they explain that deltaTime makes things dependent on time rather than the framerate.
deltaTime is simply the time between the last and the current frame. So at a framerate of 60 fps deltaTime is about 1/60 (~0.0166). If you add up deltaTime each frame you will get a value of about "1.0" after one second since "60" times "1/60" is "1". deltaTime will be updated every frame depending on how long the last frame took so on average you get a constant time based movement / increment,
Your answer
Follow this Question
Related Questions
Android/Desktop Sync Movement with Time.deltaTime 0 Answers
waitforseconds in update good for perfomance ? 2 Answers
How to shoot RayCast in center of screen? 1 Answer
Temporarily disable audio? 1 Answer