- Home /
Questions about frame rate
As update is called every frame,so if my frame rate is 70fps, does that mean update is called 70 times per second?and if anything happening inside update function,does that mean it also happens 70 times per second?
I'm confused with the following statements
void Update()
{
transform.Rotate(new Vector3(0,20,0));
}
it rotates my GameObject 20 units along y axis every frame.and if the frame rate is 70 fps,does that mean gameobject gets rotated 70 times 20 units in one second? Lets say i want to rotate the Gameobject along y axis 20 units per second, so it's done by the following statements
void Update()
{
transform.Rotate(new Vector3(0,20*Time.deltaTime,0));
}
this also gets called every frame, but what exactly multiplying the value 20 with Time.deltatime does to make the gameObject rotate 20 units per second? It's written in the documentation that Time.deltaTime returns the elapsed time since last call to the update method. What's happening here i can't seem to get insight into that, kindly make me understand.
Answer by Baste · Nov 07, 2014 at 12:35 PM
You're pretty much spot on - Update is called once every frame. More correctly: your fps is pretty much how often the game manages to call Update (and all of the other methods) on all the stuff in your game.
So 60fps means that your game's managing to call Update 60 times a second.
Now, if you want to rotate something 20 degrees each second, and you're running at 60 fps, that means that on every frame you want to rotate the same object 20/60 = 1/3 degree per frame. On the other hand, if the exact same game's running on just 30 fps, you'll want 20/30 = 2/3 degrees per frame.
This is where deltaTime comes in. Time.deltaTime is the time since the last frame. Thus, if you're running on 60 fps, Time.deltaTime will be 1/60. If you're running at 30 fps, Time.deltaTime is 1/30.
Notice here that that's exactly what you need to get the correct number of degrees per frame to rotate your object. If you do Time.deltaTime * 20, you get:
on 60 fps: 1/60 * 20 = 20/60 = 1/3
on 30 fps: 1/30 * 20 = 20/30 = 2/3
So, what multiplying with Time.deltaTime is doing for you is making sure that your object rotates at 20 degrees per second, no matter what the frame rate is. Hope that makes it clear!
Answer by robertbu · Nov 07, 2014 at 12:37 PM
Any frame rate associated with Update() will be an average or an approximation, and yes if the stats window is showing a frame rate of 70 fps, then Update() is getting called approximately 70 times per second. Things like garbage collection and loads you place on the app will make the number vary frame to frame and on average. And yes, that mean in your second example that your object is getting rotated 70 * 20 degrees every second.
As for your last example, sometimes the easiest way to figure things out by doing them by hand. So to make things easy, lets assume the frame rate is 50 fps. That means Update() is called approximately every 1/50 (0.02) seconds. And so Time.deltaTime times 20 is 0.02 times 20 is .4 degrees per frame. And if we do a .4 degree rotation 50 times, we get 20 degrees of rotation.
Your answer
![](https://koobas.hobune.stream/wayback/20220613170937im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Heya again guys how about rotation and score board 0 Answers
Need help with rotation script. 1 Answer
Rotating wrong 0 Answers
Object won't rotate z axis on second click? 2 Answers
How do I attach a character to a fps controller / make him rotate? 0 Answers