Hi, in Unity, I have been attempting to create a basic custom gravity engine to apply gravity on a local level. I have been attempting to incorporate drag into this engine so heavier objects fall faster than lighter ones. The code below partially works, except I have noticed a strange behavior where if two objects, one weighing 10kg, and another weighing 1kg, are in an area with the same fluid density, and have the same force applied to them in the same direction. The 10kg object will gain speed much faster than the 1kg object, even in directions opposite to gravity.
This does not appear to be a normal behavior. Have I done something wrong?
If you can leave a reply, I will be most grateful.
Rigidbody2D rb = other.GetComponent<Rigidbody2D>();
rb.drag = 0;
rb.AddForce(force * rb.gravityScale * rb.mass); // force is just the gravitational force in m/s
Vector2 velocity = rb.velocity;
float speed = velocity.magnitude;
// Drag equation: F_drag = 0.5 * air density * coefficient * area * velocity^2
float dragCoefficient = 0.47f;
float crossSectionalArea = other.GetComponent<GravityObject>().crossSectionalArea;
float dragForceMagnitude = 0.5f * airDensity * dragCoefficient * crossSectionalArea * speed * speed / rb.mass;
Vector2 dragForce = -dragForceMagnitude * velocity.normalized;
rb.AddForce(dragForce);