box2d: Body not slowing down with friction for static body (Bug)
It seems like there’s a bug in the following set-up, reproducible by with the default settings and Step(1/60f, 8, 8) (not the test-bed settings):
b2Vec2 gravity;
gravity.Set(0.0f, -10.0f);
m_world = new b2World(gravity);
b2ChainShape chainShape;
b2Vec2 vertices[] = {b2Vec2(-5,0), b2Vec2(5,0), b2Vec2(5,5), b2Vec2(4,1), b2Vec2(-4,1), b2Vec2(-5,5)};
chainShape.CreateLoop(vertices, 6);
b2FixtureDef groundFixtureDef;
groundFixtureDef.density = 0;
groundFixtureDef.shape = &chainShape;
b2BodyDef groundBodyDef;
groundBodyDef.type = b2_staticBody;
b2Body *groundBody = m_world->CreateBody(&groundBodyDef);
b2Fixture *groundBodyFixture = groundBody->CreateFixture(&groundFixtureDef);
b2CircleShape ballShape;
ballShape.m_radius = 1;
b2FixtureDef ballFixtureDef;
ballFixtureDef.restitution = 0.75f;
ballFixtureDef.density = 1;
ballFixtureDef.shape = &ballShape;
b2BodyDef ballBodyDef;
ballBodyDef.type = b2BodyType::b2_dynamicBody;
ballBodyDef.position = b2Vec2(0, 10);
b2Body *ball = m_world->CreateBody(&ballBodyDef);
b2Fixture *ballFixture = ball->CreateFixture(&ballFixtureDef);
ball->ApplyForceToCenter(b2Vec2(-1000, -400), true);
As you’ll see the ball at the end is meant to stop and in fact, if you choose the ground to be dynamic body instead of static, the ball will stop, but when it’s dynamic and the ball is supposed to stop it will pick up speed. Doesn’t seem related to the recent changes with density zero improvement. I was able to repro it even in previous commits to that.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (1 by maintainers)
Commits related to this issue
- Reproduce issue #604 (#617) issue #604 in dump_loader — committed to erincatto/box2d by erincatto 4 years ago
That’s reproducing right there, but you are cutting the video right when it’s about to pick up speed, the pick up in speed is very minimal, right when you cut it the ball will keep on rolling at that very slow speed until it reaches the other side, and it’ll be about 0.0001 mps faster at the end. The body never actually sleeps. You’ll notice the pick up in speed only if you console log the velocity of the ball at every frame.