# air resistance over time

This topic is 3495 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi there, I'm trying to add correct air resistance into moving objects, currently I'm just multiplying the velocity by some number between 0-1 every frame so that it reduces, which is fine but when the framerate is low the objects take longer to slow down:


void Object::update(unsigned dTimeMs)
{
this->velocity += this->acceleration * (dTimeMs/1000.0f);

this->velocity *= 0.8;

this->position += this->velocity * (dTimeMs/1000.0f);
}


I'm not looking for accurate air resistance but I need a way to scale the velocity towards zero at a fixed rate, so that the rate will remain the same when I call this function at different framerates. Any Ideas?

##### Share on other sites
Moving to Math & Physics.

##### Share on other sites
I had a similar problem for rotation. varying frame rate was the cause.

I came up with a simple super duper elegant solution. :D

Calculate the frame rate, calculate the multiplying constant wrt the frame rate.

Hope that helps.

There is always a better solution, and a better solution should be always used.

##### Share on other sites
   float airResistance = someConstant*this->velocity*this->velocity;   this->velocity += (this->acceleration-airResistance ) * (dTimeMs/1000.0f);   this->position += this->velocity * (dTimeMs/1000.0f);

"someConstant" depends on the object... but since u didnt want an accurate calculation i left that out...

##### Share on other sites
To expand on what Dragon_Strike said, the actual formula is as follows:

F = -1/2 * V^2 * A * Cd * rho

where:
F - value of the drag force [N]
V^2 - squared speed [m/s]
A - frontal area of object, where "frontal" means directed towards move direction [m^2]
Cd - drag coefficient (in range 0 - 1)
rho - density of air = 1,168 kg/m^3

As you can see A, Cd and rho can be chosen empirically so you end up with one constant as Dragon_Strike pointed out:

C = -1/2 * A * Cd * rho

And then the equation simplifies to:

F = C * V^2

##### Share on other sites
If you want frame-rate dependent damping (which isn't the same as air resistance), then you want your variable become half its original value in time T:

time t = 0, x = X
time t = T, x = X/2

over that period T, each update of time dt you multiply x by f. That means over the whole time period you want:

X * f * f * ... * f = X * f^(T/dt) = X/2

so f = 0.5^(dt/T)

i.e. each update multiply your damped variable by 0.5^(dt/T) where dt is the timestep, and T is a constant (the time you would want your variable to decay to half its original value). The bigger T is, the smaller the damping.

Obviously you only need to evaluate f once per system update, so calculating the power function shouldn't be a problem.

##### Share on other sites
It's not perfect but I often use this sort of thing. It's got a few slow function calls in it but at least it's resistant to changes in frame size

void Object::update(float timeDeltaSec){   float currentSpeed = this->velocity.Length();   float drag         = currentSpeed * currentSpeed * someDragCoefficient;   this->velocity = this->velocity * exp(-timeDeltaSec * drag);}

##### Share on other sites
Quote:
 If you want frame-rate dependent damping (which isn't the same as air resistance), then you want your variable become half its original value in time T:

Thanks, this is what I was looking for.

##### Share on other sites
What's really going on here (when you "vary the damping constant") is that you're solving a differential equation using Euler's method and a varying timestep.

1. 1
2. 2
3. 3
4. 4
Rutin
15
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633724
• Total Posts
3013556
×