| View previous topic :: View next topic |
| Author |
Message |
Mouse
Joined: 24 Nov 2007 Posts: 6
|
Posted: Sun Nov 25, 2007 9:59 pm Post subject: any way to simulate Drag or air resistance? |
|
|
Is there any way to simulate Drag or air resistance? so if you throw a projectile through the air will it slow down?
EDIT: Better example would be something moving through water. |
|
| Back to top |
|
 |
luke Site Admin
Joined: 15 Oct 2004 Posts: 621
|
Posted: Wed Nov 28, 2007 10:51 am Post subject: |
|
|
There is no in build method, however, you can do it your self.
Here is a fairly simple and generic method for approximating air resistance.
| Code: |
const float fAirResistance = 0.01f; // what every value you like
const Vec3& v3LinearVelocity = pDynamicObject->GetLinearVelocity();
float fSpeed = v3LinearVelocity.GetMagnitude();
if (fSpeed > 0.0f)
{
Vec3 v3VelocityDirection = v3LinearVelocity / fSpeed;
fSpeed -= fAirResistance * fSpeed * fSpeed * fDt; // this could be replace with any formular for air or fluid resistance
if (fSpeed < 0.0f)
fSpeed = 0.0f;
// fSpeed *= exp(-fAirResistance * fDt); // Alternative drag formular
pDynamicObject->SetLinearVelocity(v3VelocityDirection * fSpeed;
}
|
|
|
| Back to top |
|
 |
Mouse
Joined: 24 Nov 2007 Posts: 6
|
Posted: Wed Nov 28, 2007 3:14 pm Post subject: |
|
|
| That's was I was thinking of doing - except that I was going to apply a reverse force for the drag rather than change the velocity explictly - but this way might be easier. |
|
| Back to top |
|
 |
luke Site Admin
Joined: 15 Oct 2004 Posts: 621
|
Posted: Thu Nov 29, 2007 2:03 am Post subject: |
|
|
| Either way. But setting the velocity directly sometimes makes life easier. |
|
| Back to top |
|
 |
|