- Home /
How to programmatically find fixedUpdate rate?
At the moment, I am calculating the average speed of my car (in a simulator).
At each fixedUpdate,
double TotalSpeed;
double startTime;
double currentTime;
void fixedUpdate(){
TotalSpeed+= getCurrentSpeed;
}
double avg(){
double totalTime = currentTime-startTime;
double avgSpeedPerSecond = (TotalSpeed/(FIXED_UPDATE_RATE*totalTime))
return avgSpeedPerSecond;
}
You can clearly see it is crucial to know the FIXED_UPDATE_RATE. I know that i can check it manually in the editor (default is 50). But how would you access it programmatically (e.g. UnityEngine.FixedUpdateRate() or something...)
Answer by Kryptos · Apr 18, 2012 at 08:07 AM
Time.fixedDeltaTime
gives the ideal delta time between two fixed updates.
Inside FixedUpdate
method, Time.deltaTime
gives the real delta time since the last fixed update.
See http://unity3d.com/support/documentation/ScriptReference/Time.html
deltaTime gives the time since the last update and not fixed update... http://unity3d.com/support/documentation/$$anonymous$$anual/Update%20Order.html
(these are two different updates)
deltaTime run within the FixedUpdate method does give the delta between this FixedUpdate and the last FixedUpdate! (http://unity3d.com/support/documentation/ScriptReference/Time-deltaTime.html)
Thanks, i was aware of using Time.deltaTime to make frame-rate independent stuff for Update but was not aware that i could use it for fixedUpdate and hence make everything more accurate.
Your answer
Follow this Question
Related Questions
Mesh with texture atlas is "sparkling" 1 Answer
Determinism problems: Mathf, Unity.Random VS Math, System.Random 2 Answers
Rigidbody.AddForceAtPosition & functions 1 Answer
Why won't my door open? 1 Answer
detection raycast too late 2 Answers