Hello,
I know this question has been asked before, but I am still confused about the Time.deltaTime function. So I understand how it makes something frame independent. I don’t understand why we can’t use an alternate method to achieve the exact same result.
For example, suppose the frame rate for the scene is 24 fps. Why can’t we just divide the value (which we would otherwise multiply with Time.deltaTime) by 24? Would it not achieve the same result?
So, for example, the original code looks like this:
function Update () {
// Move the object 10 meters per second!
var translation : float = Time.deltaTime * 10;
transform.Translate (0, 0, translation);
}
But I think it can be written like this to behave no differently:
function Update () {
// Move the object 10 meters per second!
var translation : float = (1/24) * 10;
transform.Translate (0, 0, translation);
}
Of course, if the frame rate is not 24, replace the 24 with whatever else you want.
The only advantage I see of Time.deltaTime is that if we change the frame rate, it’s a little bit easier to keep the code more flexible. But it can be achieved by setting the frame rate in a global variable and dividing by it instead of a raw number (i.e. 24).
So what is the flaw in my logic here? Can the frame rate change on different devices or something?
Thank you so much!