How would you fake air resistance? (c#)

Ive got a helicopter using two speeds, Helispeed (pitch foward/back speed) and heliRollSpeed (roll left/right speed), But im trying to add a air resistance element to them so you start to slow down if you are leveling out the heli, But cant work out how to add this in well.

This is how i get the speeds (almost identical for ptich/roll):

``````	pitch = heli.transform.eulerAngles.x;

if((pitch > 0) && (pitch < 90)){

float temp = (60 - Mathf.Abs((pitch - 45) / 0.75f)) / 100;

heliSpeed = heliSpeed + temp;

if(heliSpeed > 40.0f) { heliSpeed = 40.0f; }

} else if((pitch > 180) && (pitch < 360)) {

float temp = (60 - Mathf.Abs((pitch - 405.0f) / 0.75f)) / 100;

heliSpeed = heliSpeed + temp;

if(heliSpeed < -40.0f) { heliSpeed = -40.0f; }

}

if(heliSpeed < 0){
heli.transform.Translate(-Vector3.forward * -heliSpeed * Time.deltaTime);
} else {
heli.transform.Translate(Vector3.forward * heliSpeed * Time.deltaTime);
}
``````

But the speed will always increase if you are not at 0 degrees. So i tried adding this to a lateUpdate

``````if(heliSpeed > 0.01){ heliSpeed -= (heli.rigidbody.drag / heliSpeed); } else if (heliSpeed < -0.01) { heliSpeed += (heli.rigidbody.drag / heliSpeed); }
if(helirollSpeed > 0.01){ helirollSpeed -= (heli.rigidbody.drag / helirollSpeed); } else if (helirollSpeed < -0.01) { helirollSpeed += (heli.rigidbody.drag / helirollSpeed); }
``````

but without thinking, this just means you cant move in any direction, it just shoots you in the opposite direction.

Rigidbodies have a drag value, which is exactly that:

If you’d want to do this manually for some reason, simply apply force in the direction opposite of the velocity, in proportion to the current speed. If you care about exact formulas, learn about them here:

I made a post on the forums about applying drag manually with an equation that works exactly like Unity’s.

``````velocity -= Vector3.ClampMagnitude(velocity, 1) * drag * Time.deltaTime;