- Home /
FixedUpdate and Time.deltaTime slowe
I am moving rigidbodies around with velocity.
Is simply using
function FixedUpdate(){
thisRigidbody.velocity.x = movement.x;
}
enough to make the movement framerate INDEPENDENT. versus
function FixedUpdate(){
thisRigidbody.velocity.x = movement.x * Time.deltaTime;
}
Which seems to slowdown my game.
Thanks in advance!
Answer by Broheim · Oct 04, 2012 at 12:06 PM
The FixedUpdate already is framerate-independent. I suggest you try to learn the exact difference between Update() and FixedUpdate (). They correspond to Time.deltaTime and Time.fixedDeltaTime.
EDIT: like Kryptos pointed out, the Time.deltaTime inside a FixedUpate indeed does return the fixed timestep as mentioned in the documentation. I wasn't aware of that.
thanks! I was just making sure and correcting some errors from earlier coding.
This answer is wrong. Inside FixedUpdate, Time.deltaTime
is not framerate-dependent. It is (almost) the same as Time.fixedDeltaTime
.
See documentation: Time.deltaTime
FixedUpdate is not getting called every frame whereas Update does. Therefore there is no reason to use the deltaTime value in a FixedUpdate which is already time dependent.
@sarper. Nope this has nothing to do with that. Time.deltaTime DOES mean something inside FixedUpdate. But this does not make sense to use it for a velocity, unless movement represents an acceleration.
Yes, the answer is wrong. I just printed `Time.deltaTime` inside of Update/fixedUpdate. InFixed, it changes into exactly 0.02 (the value of `fixedDeltaTime.)
In other words, the code would be wrong for not using "fixed" in front of `deltaTime,` but Unity has your back, and the code works fine. The real error is not realizing velocity already has a secret `T.fDt` in the physics step.
Answer by Kryptos · Oct 04, 2012 at 01:51 PM
It is slower with Time.deltaTime because this value is always lesser than 1.
In fact it does not make sense to set the velocity using Time.deltaTime since a velocity is already integrating the time. You need to use this value when you set a position using a value that is a velocity. This is basic middle school physics:
*velocity* is a value which unit is in **m/s** <br>
*time* is a value which unit is in **s** <br>
*position* is a value which unit is in meters (m) <br>
----
Therefore: <br>
*position* = *velocity* * *time* (m = m/s * s) <br>
It would make sense if movement
was an acceleration vector, but I don't think that it is the case here.
Never$$anonymous$$d the previous comment, I thought FixedUpdate was getting called every fixed timestep, it seems it gets called every fixed framerate frame so it's not time dependent. You are correct, thank you!
Thanks! SO I guess using velocity Time.deltaTime is not necessary! Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613081851im_/https://answers.unity.com/themes/thub/images/avi.jpg)