• 14
• 12
• 9
• 10
• 13

# Bullet physics lib: getting a ball to roll

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

## 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));
body->setAngularFactor(1.0);

// 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();
++i)
{
btTransform(btQuaternion(), btVector3(i->x, i->y, i->z)),
&boxShape);
}

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)
{
world.update(timestep);
accumulator -= timestep;
}