Which formula to use for drag simulation each frame?

Viewed 595

My rigidbody has a velocity and I defined a variable float drag = 0.995f so that:

void FixedUpdate(){
    rb.velocity *= drag;
}

It's working fine but I guess I have to use Time.deltaTime to make the drag time-consistent, so my question is how to write a time-consistent drag formula? Should I just set drag as a really big value and write rb.velocity *= drag * Time.deltaTime and tune drag until I'm satisfied?

I just thought of using rb.velocity *= (1 - drag * Time.deltaTime) and it seems to be working fine.

1 Answers

Both will work.

Since you're using FixedUpdate you'll also want to use fixedDeltaTime instead of deltaTime.

rb.velocity *= drag * Time.fixedDeltaTime;
rb.velocity *= (1 - drag * Time.fixedDeltaTime);

Which formula you use is really up to personal preference. Be aware the first one will decrease the actual drag as the drag value increases.

Related