Does FIxedUpdate get called every 0.02 seconds?
Hey everyone, I know there are a bunch of questions out there relating to fixedupdate vs update, but I can't seem to find the answer to my question. I have run unity on many different computers (PC's and Macs), and every time it shows fixedupdate as triggering every 0.02 seconds. Is this set, or could this be different?
I'm currently running code for slowing down movement by the following:
velocity.x = velocity.x * 0.95
This is giving me exactly the desired effect when I use it in FixedUpdate, but I know that this code relies upon the fact that FixedUpdate gets called every 0.02 seconds...
so...
1) Does FixedUpdate get called avery 0.02 seconds? 2) If not, should I use Time.deltaTime or Time.fixedDeltaTime inside of FixedUpdate? 3) Is there a better way to do this, but still get the desired effect? I swear I'm having a brain fart.
Thanks!!!
Answer by LK84 · Dec 29, 2016 at 04:20 PM
You can change your Fixed TimeStep under Edit-->Project Settings-->Time
Inside FixedUpdate using Time.fixedDeltaTime usually makes most sense. When you are doing any kind of physics calculations, FixedUpdate() should be your choice.
Thanks for your answer..That definitely helps...Just out of curiousity...Since Time.fixedDeltaTime in FixedUpdate and Time.deltaTime in Update are essentially the same thing (showing the time elapsed since the last time that function is called), why bother doing one vs the other? Sorry if my question seems obvious, I am just having a hard time wrapping my head around it!!
Wrong. Time.fixedDeltaTime tells the theoretical time between fixed updates, not the elapsed time. Thats why you should user Time.deltaTime even in FixedUpdate.
It doesn't matter what you use in FixedUpdate. Time.deltaTime will return the same as fixedDeltaTime when used in a FixedUpdate function.
Answer by ScaniX · Dec 29, 2016 at 04:26 PM
This depends on two things:
Your setting for the physics frequency
The performance of the computer
The faster the computer is the more precisely it is called every N (1/physicsFPS) seconds. The contract however is that it is called a certain amount per second and it can even "pile up" (correct me if I'm wrong here) if there is too much to do in the fixed update or the computer is very slow.
You should use Time.fixedDeltaTime as Time.deltaTime will only contain the delta for the most recent frame.
Thank you very much for the response. I asked a followup question in the answer above and if you had an answer to that, I'd appreciate it too!
Well, to say it in your words:
Time.fixedDeltaTime is the time since the last time the FixedUpdate() was called.
Time.deltaTime is the time since the last time the Update() was called.
The values differ as those two methods are not called in the same way. Update() is called for each frame which is usually as often as possible for the engine (probably limited by vsync or other explicit limits only) while FixedUpdate() tries to honor your frequency setting and is usually called once every N frames.
Cool...but, theoretically, over one second of time, the object should move the same distance...I suppose the only difference, is that fixedUpdate will be more true to the final call, as update may be called slightly later or earlier (thus giving a slight variation in the final distance)...Thoughts?
Thanks...