air friction formulas ?

Hi,

what can be the formula of air friction?

we say that i have 2 value

vel = velocity (vector)
friction = 0.01

the friction must increase as the velocity increase …

thanks

You could just take the air friction as a percentage of the velocity. so

friction = vel * 0.05 

just makes friction 5 percent of the velocity. This is the most simple solution I can think of, but I’m sure its possible to model realistic air friction, but that would take some research and googling on your part. You would have to take into account the size of an object, the air temperature, altitude … but that would only be required if your doing some highly realistic simulations. maybe you are???

As a rule of thumb, the effects of air resistance are proportional to the velocity squared, i.e.,

friction = velocity * velocity * DRAG_COEFFICIENT

where DRAG_COEFFICIENT is a predefined constant.

Look up “Drag equation” on Wikipedia for more details.

yes klauser ,good idea, for that i open a TD, i have a formula but much more complicated … too complicated :smiley:

calculating a friction as “percentage” to substract is very easy


def m(cont):
    own = cont.owner
    
    vel = own.worldLinearVelocity
    
    friction = 0.05 * vel
    
    vel -= friction  

:wink:

Or,

velocity = own.worldLinearVelocity * 0.95

uhm…

i have the suspect that is too easy
the percentage not should increase also ?

something as :
1 m/s : friction = 0.0000000001 (almost nothing)
100 m/s friction = 0.08

or not?

It should, after all checking a drag equation through fluids, one can see the velocity of the object as a factor.
When you’re next in a car, hold your hand out the window. The faster you go, the more force you feel on your hand.
http://upload.wikimedia.org/math/9/9/a/99a6015b6a230860c9b1517b238e5de9.png

in python syntax?

is correct?


import bge


def m(cont):
    own = cont.owner
    
    vel = own.worldLinearVelocity
    mag = vel.magnitude
    
    friction = vel*mag*0.005
    
    vel -= friction

vel*mag == vel

because

vel is a vector of size mag

Myself I would just invert the velocity vector, scale it down a little, and apply a force based on it. That would let bullet do the work of how much it will impact the actual motion.

vel is not normalized!

vel*mag == vel.normalized()magmag

:wink:

PS: i make a bit of mix because >> vector * vector = float …instead better keep the vector

You are right, this is indeed true.

But wouldn’t that

  • decrease the vector if it is below 1 and
  • increase the vector when it is above 1?

[QUOTE=Monster;2216656]You are right, this is indeed true.

Edit: never mind

under 1 not happen nothing of wrong

maybe with high number can be a bit strange (but maybe is right)

return the velocity after calculating the friction…(only with float)


def friction( vel ) :
    return vel - vel * vel * 0.005

>>> friction(0.1)
0.09995000000000001

>>> friction(5)
4.875

>>> friction(10)
9.5

>>> friction(50)
37.5

>>> friction(150)
37.5

>>> friction(200)
0.0

>>> friction(300)
-150.0

if the velocity magnitude is more than 400 become crazy…

>>> friction(401)
-403.005

(max speed and gravity = terminal velocity) + additional force
whereby friction & drag depending on atmosphere thickness.
however speed in a vacuum are possibly infinite.

Hi

Basic formula
p = 1.22 # air density at sea level kg/m3
a = 0.31415 # area(m2) of 5 cm radius sphere /cannon ball
Cd = 0.47 # drag coefficient for sphere
v = 12.0 # velocity ms

Drag = 0.5 * p * v**2 * a * Cd

If area and Cd are not changing, meaning the attitude towards motion is not changing or object is a shpere and also if altitude is constant, then the p * a * Cd * 0.5 can pre calculate in initial phase and main loop code will be very simple.

Drag = 0.09006 * v**2

I’m wrong or with this formula the “limit” of speed is 12 m/s ?

if the speed is > 12 m/s the drag > of velocity (bounce backward)

more or less in a medium gun (i read this) a bullet start with 300 m/s and tounch the ground after 2 km

The v is just a variable for your dynamic object forward axis velocity.

Hi

I made a test script for the b263+, which is calculating sphere’s drag per local axes.


import bge

cont = bge.logic.getCurrentController()
own = cont.owner

def drag(v): # cal drag with preset value
	try:
		return v**2 * -0.090066805 * (v/abs(v))
	except ZeroDivisionError:
		return 0.0

# get local velocities
v = own.localLinearVelocity

# apply local linear forces
own.applyForce([drag((v[0]), drag(v[1]), drag(v[2])], 1)

OK

this last work subdividing the constant number by 60
0.09 / 60

a obj-bullet shot at 300 m/s (45° of angle) fall about at 1.2 km

:wink: