Getting a ball to roll (newb)

riku
Posts: 2
Joined: Thu Jul 31, 2008 4:12 pm

Getting a ball to roll (newb)

Post by riku »

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.

Code: Select all

// 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)
{
    shape.addChildShape(
       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);

world.addRigidBody(level.body.get());
world.addRigidBody(ball.body.get());

// In my main loop
        while(accumulator >= timestep)
        {
            world.update(timestep);
            accumulator -= timestep;
        }
Thanks in advance,
-Riku
edit: added missing parts of code