• Advertisement
Sign in to follow this  

Bullet physics lib: getting a ball to roll

This topic is 3457 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is a cross post from the Bullet physics library forums. I havn't got any answers there and I havn't had success finding the solution elsewhere, so I decided to try here. Original posting at http://bulletphysics.com/Bullet/phpBB3/viewtopic.php?t=2427 Hi! I am building a small game with a ball rolling on a level. I have set up a rigid body with a btSphereShape shape and a level (rigid body with zero mass) that has a btCompoundShape shape that consists of a half dozen btBoxShapes. The level can be rotated by the player. My simulation runs fine, the ball drops with gravity and hits the boxes, the level moves fine and the ball bounces on top of the level. However, my ball does not roll. The ball just gets stuck to the level and sliding downwards. Adjusting my friction, restitution and damping parameters changes the simulation as expected. Sometimes the ball gets stuck to the level and there is some interpenetration. However, this is not always the case and most of the time there's no interpenetration or other glitches and everything seems like it should, except that my ball does not roll. What can I do to make my ball roll? Here's the relevant parts of my code, it's not complete but should have almost all my bullet-relevant code.
// Ball creation
btSphereShape shape(0.5);
btDefaultMotionState state(btTransform(btQuaternion(), btVector3(x, y, z)))
boost::scoped_ptr<btRigidBody> body;

btRigidBody::btRigidBodyConstructionInfo desc(mass, &state, &shape);
desc.m_linearDamping = 0.5;
desc.m_friction = 0.5;
desc.m_restitution = 0.3;
body.reset(new btRigidBody(desc));

// Level creation
btBoxShape boxShape(btVector3(0.5, 0.5, 0.5));
btDefaultMotionState state(btTransform(btQuaternion(), btVector3(x, y, z)));
btCompoundShape shape;
boost::scoped_ptr<btRigidBody> body;

for(std::vector<box_t>::const_iterator i = boxes.begin();
    i != boxes.end();
       btTransform(btQuaternion(), btVector3(i->x, i->y, i->z)),
btRigidBody::btRigidBodyConstructionInfo desc(0.0, &state, &shape);
desc.m_friction = 1.0;
desc.m_restitution = 0.1;
body.reset(new btRigidBody(desc));

// World creation
btDefaultCollisionConfiguration config;
btCollisionDispatcher dispatcher(&config);
btAxisSweep3 pairCache(btPoint3(-100, -100, -100), btPoint3(100, 100, 100));
btDiscreteDynamicsWorld world(&dispatcher, &pairCache, &solver, &config);


// In my main loop
        while(accumulator >= timestep)
            accumulator -= timestep;
Thanks in advance, -Riku

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement