This project is read-only.

Do colliding objects ever come to rest?

Jan 16, 2011 at 7:25 AM

I have a polygon body that gets shot out of a cannon, and will bounce off the floor below. After 4/5 bounces the objects will come to rest in the Y access, but always continues to glide on the surface as if it is on ice. 

From what I understand, setting the friction on the two bodies should cause the moving body to eventually come to a rest, but even after setting both bodies to a friction of 1 nothing happens.

My two bodies are defined like:

 

var def = new BodyDef() { type = BodyType.Dynamic };
var shape = new CircleShape() { _radius = 50 * Constants.Scale };
var fix = new FixtureDef();
fix.friction = .4f;
fix.restitution = .6f;
fix.density = 1f;
fix.shape = shape;
body1 = World.CreateBody(def);
body1.CreateFixture(fix);



var grounDef = new BodyDef();
grounDef.type = BodyType.Static;
var groundFix = new FixtureDef();
groundFix.restitution = .4f;
groundFix.friction = .6f;
groundFix.density = 0f;
var groundShape = new PolygonShape();
groundShape.SetAsEdge(new Vector2(0f, 0f), new Vector2(8f, 0f));
body2 = World.CreateBody(grounDef);
groundFix.shape = groundShape;
body2.CreateFixture(groundFix);

Jan 16, 2011 at 8:02 AM

They never come to rest in the sense that the iterative solver will constantly be repositioning them, but it should be at the sub-pixel level for something like a block resting on the ground.

Your code sample shows that you're creating a circle, are you sure its not rolling along the ground?  Even with high friction a perfect circle against a flat surface will roll for quite some time.  You could add angular dampening to the body if that is the case.

Jan 16, 2011 at 8:03 AM

Also, under normal circumstances the solver will say "good enough" and put the body to sleep at which point it truly is at rest (but for a complex collision this can take a long time).

Jan 16, 2011 at 10:23 PM

It isn't moving at a sub pixel level. since it is a ball, it is probably rolling, but I don't get why it never stops (i let it go for 5 minutes). Does it have anything to do with the mass?

Jan 17, 2011 at 4:03 AM

A ball rolling is not affected very much by friction, you'll want to put some angular dampening on the body definition.  In real life there is usually some linear air resistance as well that would offset the rolling.

Sliding objects will stop based on friction, but rolling objects (in particular perfect circles) will require something else if you want them to quickly come to a stop.

Jan 17, 2011 at 5:35 AM

that did it, thanks