- Home /
Rigidbody drag and TimeManager.FixedTimeStep
Try this:
Drag 30, timestep 0.02: fine, rigidbody moves
Drag 30, timestep 0.1: rigidbody stops completely, regardless of external forces
Isn't this kind of silly? I thought the physics engine would have at least implemented a timestep-size independent damping simulation.
How can I make a result that independent on FixedTimeStep value?
Answer by paulkopetko · Sep 28, 2016 at 03:35 PM
From some brief testing I've done on this issue today, I suspect Unity's drag factor is hardcoded to a timestep of 0.02, and not Time.fixedDeltaTime. Specifically, I think it's calculated like this at the end of each FixedUpdate() loop:
velocity *= 1 / (1 + drag * 0.02f);
So, assuming you don't want to write your own physics system, you could manually adjust your Rigidbody drag values based on the new, non-default fixed timestep value. In your example above, drag = 30 @ 0.02s timestep should be the same as drag = 6 @ 0.1s timestep.
You could do this at runtime for each Rigidbody like so:
Start() {
GetComponent<Rigidbody2D>().drag *= 0.02f / Time.fixedDeltaTime;
}
Hope that helps.