A newbie question: Friction problems?

Xilliah
Posts: 5
Joined: Fri Apr 18, 2008 11:20 am

A newbie question: Friction problems?

Post by Xilliah »

Hello,

I have been trying to squeeze Bullet into my engine and the test was/is to make 2 boxes fall, one heavier than the other. The heavier one would be above the lighter one and the effect should be that they hit each other and show some interaction.

However, they are both moving at the same speed, no matter what the mass is, as if in a vacuum. I have been looking around, but I noticed that the friction of bodies set to 0.5 by default. What gives?

Sorry if this question is too basic for your taste. But there simply ísn't any good doc,
Xilliah

EDIT:
Do I have to create the air friction manually?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: A newbie question: Friction problems?

Post by Erwin Coumans »

The friction for a rigid body in Bullet is just contact friction.

There is no real air friction for rigid bodies (but there is an aero dynamics demo for cloth).
You can set some linear damping (or apply impulses/forces) to mimick this effect.

Hope this helps,
Erwin
Xilliah
Posts: 5
Joined: Fri Apr 18, 2008 11:20 am

Re: A newbie question: Friction problems?

Post by Xilliah »

I have been using linear dampening but as you say this isn't really air friction.

But why isn't there some kind of air friction in Bullet? You need it in most cases.
Oogst
Posts: 25
Joined: Thu Apr 10, 2008 11:19 am
Location: Utrecht, Netherlands

Re: A newbie question: Friction problems?

Post by Oogst »

Air friction is incredibly difficult to do, because it depends on the shape of the object and the angle under which it is moving and in fact also on things like turbulence and material smoothness. Simulating that correctly is something I never heard of anyone doing for games or something real-time, so as an alternative, people are expected to just do their own air friction and figure out what they want with it. Sounds reasonable to me. Common solutions would be to subtract a standard amount from the speed each frame, or to multiply with a number like 0.99 each frame, also slowly lowering the speed.
colinvella
Posts: 24
Joined: Sat Feb 09, 2008 2:38 pm
Location: Malta

Re: A newbie question: Friction problems?

Post by colinvella »

Assuming you have polyhedral geometry (like the cubes in your case), you could try building a simple aerodynamic model as follows:

For every face:
1) compute a face centroid.. for a triangular face this can by done by taking the mean of the vertices
2) compute the body's velocity at the centroid
3) subtract the fluid velocity from the centroid velocity to get a relative velocity - if we assume a static fluid e.g. air with no wind, we can take fluid velocity to be zero
4) compute a cosine of the relative centroid velocity with the face normal - this can be done by taking a dot product between face normal and normalised relative centroid velocity
5) compute a friction force scalar value using a simple air friction model e.g. f = -k a v^2 where "k" is some friction coefficient of your choosing and "a" is the area of the face.
6) compute the required friction by multiplying the force scalar value with the face normal - this produces a friction force vector in the direction of the face normal as if the face was travelling through the fluid head-on
7) multiply the friction force vector with the cosine in step (4).. this simulates the effect of the face travelling through the fluid at the actual angle so that a face with a normal perpendicular to the relative centroid velocity will not produce friction, e.g. like the side of a car

This approach produces an approximate model without taking turbulence into account. It's accuracy is also dependend on the complexity of the geometry. For instance, a 6-faced cube will not feel any friction if spinning on itself. However, if the cube is tessellated into smaller faces, the sub-faces "facing the wind" will induce a reactive friction force that will slow down the rotation.

I actually tried implementing such a model in a 2D simulator, using edges instead of faces, and edge lenghts instead of face areas, however the concept should be the same. I'm attaching a link to a screenshot illustrating the model in action:

http://tkfiles.storage.live.com/y1pB07f ... GlWCEI8lVc

edit: the attached screenshot illustrates a biplane model in flight. The coloured arrows indicate forces of different types. The red arrows are tension forces, orange arrows are compression forces, magenta arrows are induced propulsion, and the cyan arrows are the aerodynamic forces generated as per the model I described above.