How exactly does Rigidbody Drag works?

I’m working on script which would allow me to move rigidbody to given targed position using forces. I’m planning to do it by building control system with PID controller in Matlab, find correct parameters there and then script it in Unity3d. But to do this I’d need to know transfer function, i.e. how exactly force and parameters like mass or drag influence the movement of my rigidbody. I believe that I can easily calculate such function if only applied force is to be considered. But drag is a problem to me, because I don’t know how exactly does it work. I’m not physicist, I have only some basic knowledge about it, so it’s quite difficult for me to understand drag in Unity3d. I’ve tried to test it against drag equations for small Reynolds numbers (F = -d*v) by giving my object constant velocity in Start() function and then adding following force in every FixedUpdate

GetComponent<Rigidbody> ().AddForce (GetComponent<Rigidbody> ().drag * GetComponent<Rigidbody>().velocity);

If Unity3d’s drag had followed mentioned equation, then object’s velocity would stay constant, as force opposing drag force would be applied all the time. And it worked perfectly for low values of drag (drag < 0) and mass equal to 1. But changing mass or drag parameter lead to changes in object’s velocity, so this equation was no longer correct.

Does anyone know how exaclty Unity3d’s drag parameter influence movement of rigidbody? Is there any kind of equation which I could use in my system?

For what it is worth, I ran into a similar problem when working with Unity’s drag parameter. The drag parameter calculation that Unity uses does not seem to behave according to the Generalized Drag Calculation (which is fair considering that Unity is a Game Engine)

I resorted to setting the drag coefficient to 0 on the rigidbody and implemented the above mentioned calculation. In addition, I also included Density of Air Calculation into my drag calculation.

Using the two aforementioned calculations I ended up with a model that corresponded very well with the actual data I had.

here’s a unity forum link of an Answer from NASA :slight_smile:

i searched for a lot of time and make some calculations for all this days, and i figurer out how it wokrs (or the most closelly of it)

bascaally the calc of gravity and drag it´s:

Vector3 GForce = rb.velocity + Physics.Gravity*Time.fixedDeltaTime;
//This wil be our gravity Force applied to the RigidBody
//Similar to rb.velocity += Physics.Gravity*Time.fixedDeltaTime
//but insted to apply to rigidbody we aplly the Drag Force, so:

Vector3 vWithDrag = GForce * (GForce*(Time.fixedDeltaTIme*rb.drag));

//and finnaly we aplly to it:
rb.velocity = vWithDrag;