Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Is this the proper way to add air resistance to a ball?

Discussion in 'Physics' started by FreeGameDev, May 30, 2020.

  1. FreeGameDev


    Dec 1, 2015
    Can anyone tell me if this is the proper way to add air drag to my rigidbody(rb)?
    Here is my code:
    Code (CSharp):
    2.     private void FixedUpdate()
    3.     {
    4.         //Cd = 0.24f                        // drag coefficient of a golf ball
    5.         //A = Pi*radius*radius              // crossSectionalArea of sphere in [m^2]
    6.         //ad.p = 1.225f                     // air density in [kg/m^3]
    7.         float A = b.crossSectionalArea;    
    8.         Vector3 v;
    9.         //_P.AirResistance = 0.5f * Cd * A * v * v * ρ
    10.         v.x = -_P.AirResistance(b.Cd, A, rb.velocity.x, ad.p);
    11.         v.y = -_P.AirResistance(b.Cd, A, rb.velocity.y, ad.p);
    12.         v.z = -_P.AirResistance(b.Cd, A, rb.velocity.z, ad.p);
    13.         rb.AddForce(v.x, v.y, v.z);
    14.     }
    I did an experiment to add gravity.
    Code (CSharp):
    1. rb.AddForce(Physics.gravity * rb.mass);
    This worked exactly as unity's gravity.
    The air drag seams to be a little on the strong side?
    Also: Is there a air drag simulator that I can test my results against?

  2. FreeGameDev


    Dec 1, 2015
    Figured it out one issue: The force needs to work in the opposite direction to the velocity.
    I corrected this by Mathf.Abs(velocity.x) on of the velocities being squared. Are there still issues?
    Last edited: May 30, 2020