# Application.targetFrameRate slows down FixedUpdate and physics simulation!

I set Application.targetFrameRate = 30 to try to remove some stuttering in my 2D game; however, when I did this, all physics simulation also is slowed down! The physics are running at about 0.5 normal speed too. This seems rather strange! I’m only using rigidbodies 2D and only setting their velocity, so it’s not something stupid as me setting positions in Update().

It seems as if Time.time is slowed down by (60 / targetFrameRate)! Really weird! :S

Ok. Frame rate means how many frames are called in a fixed time period (very very usually a second). If you change the frame rate your codes will be called more or less frequently. This is why we do physics in fixedUpdate instead of update, because frame rate in update changes constantly, (and actually this is why Time.deltaTime is there for.).

Similar to “Time.deltaTime”, there is a “Time.fixedDeltaTime”. If you want your codes to do same thing all the time, no matter if frame rate changes or not, you must duplicate you final variables and vectors that you use to do things in game by “Time.fixedDeltaTime”.

Why?
Let’s think that we have a code like this:

``````    public float f = 0;

void FakeUpdate()
{
f++;
}
``````

If we adjust our frame rate to 20, and if it’s absolutely called 20 times in a second, we will have “f = 20” result at the end of a second.

Let’s change the frame rate to 30… What happened? Same code, same things happen but it give the result “f = 30”. Why? Because our code runs a constant code every frame not depending on frame rate.

Let’s look at this code piece:

``````    public float f = 0;

void FakeUpdate()
{
f += 1 * Time.deltaTime;
}
``````

If we set our frame rate to 20, 30, 40… we will always have “f = 1” result in the end. Why? Because we do this in every frame: `f = f + (1 * (1/frameRate))` , and at the end our f equals this: `f = 1 * (1/frameRate) * frameRate`. frameRates neutralize themselves and we will have a constant “1” at the end. That means no matter what your frame rate is, you will have “f = 1” at the end.

Best wishes.

I dont understand. I have the same problem even if I multiply everything by deltaTime.

Can this be related to my timesteps settings? I have 0.01667 for fixed timestep and 0.01667 for max allowed.

If I set Application.targetFrameRate= 10, everything is slow motion.