To calculate air friction, you must convert your movement vector into a magnitude, (speed) and a direction normal.
You then apply air friction like so:
Const UNITS_PER_METER# = 1.0
Const GRAVITY# = 9.8 * UNITS_PER_METER#
Const AIR_FRICTION_CONSTANT# = 0.005
Air_Friction_Force# = AIR_FRICTION_CONSTANT# * ThisPlayer\Speed#^2.0
ThisPlayer\Speed# = ThisPlayer\Speed# - (Air_Friction_Force# * Time_Delta_Sec#)
Time_Delta_Sec# is the fractional seconds which elapsed last frame. So if the last frame lasted 100 milliseconds, then it would be 0.1.
Speed# is in units per second, which conveiently for me is also meters per second, because I use a scale of 1 unit = one meter.
Note that air friction is expoential. Your vehicle will increase to a certain speed quickly, begin to slow it's acceleration, and reach a constant speed. Then when you let off the gas, you will slow down quickly, but coast along for what seems like forever at a lower rate of speed.
This is kind of sucky for games, so even in my hover racing game, I ALSO simulate ground friction even though the vehicle does not touch the ground. Ground friction will not stop the vehicle from accelerating forever, but when the vehicle slows down it takes over and makes it quickly screech to a halt.
So the two can compliment eachother. But if you're making an airplane sim, then all you want really is air friction.
Here is ground friction in case you want it:
; Compute the effect of land friction. Land friction is not dependent on speed.
ThisPlayer\Speed# = ThisPlayer\Speed# - (2.0 * Time_Delta_Sec#)
Add new thrust each frame AFTER computing the friction's effect on the vector from the previous frame.
You then apply air friction like so:
Const UNITS_PER_METER# = 1.0
Const GRAVITY# = 9.8 * UNITS_PER_METER#
Const AIR_FRICTION_CONSTANT# = 0.005
Air_Friction_Force# = AIR_FRICTION_CONSTANT# * ThisPlayer\Speed#^2.0
ThisPlayer\Speed# = ThisPlayer\Speed# - (Air_Friction_Force# * Time_Delta_Sec#)
Time_Delta_Sec# is the fractional seconds which elapsed last frame. So if the last frame lasted 100 milliseconds, then it would be 0.1.
Speed# is in units per second, which conveiently for me is also meters per second, because I use a scale of 1 unit = one meter.
Note that air friction is expoential. Your vehicle will increase to a certain speed quickly, begin to slow it's acceleration, and reach a constant speed. Then when you let off the gas, you will slow down quickly, but coast along for what seems like forever at a lower rate of speed.
This is kind of sucky for games, so even in my hover racing game, I ALSO simulate ground friction even though the vehicle does not touch the ground. Ground friction will not stop the vehicle from accelerating forever, but when the vehicle slows down it takes over and makes it quickly screech to a halt.
So the two can compliment eachother. But if you're making an airplane sim, then all you want really is air friction.
Here is ground friction in case you want it:
; Compute the effect of land friction. Land friction is not dependent on speed.
ThisPlayer\Speed# = ThisPlayer\Speed# - (2.0 * Time_Delta_Sec#)
Add new thrust each frame AFTER computing the friction's effect on the vector from the previous frame.