Quadratic drag

Hello, could someone give me the code to implement the quadratic drag such as shown in:

my attempt so far is:

var dragForceMagnitude = GetComponent().velocity.sqrMagnitude * quad_drag;

GetComponent().velocity = GetComponent().velocity * Mathf.Clamp01(1f-dragForceMagnitude/20 * Time.fixedDeltaTime);

1 Like

I got a reply from the author himself, and here’s the answer:

It’s nothing complex, you just want a force that pushes against the direction an object is moving, that scales with the square of its speed.

So, do this in FixedUpdate:

float drag = -0.1f; //(or some other negative number, you’ll need to tune it)
Vector3 force = drag * myRigidbody.velocity.normalized * myRigidbody.velocity.sqrMagnitude;
myRigidbody.ApplyForce(force);

Just use a Vector2 for 2D physics.

4 Likes