5
\$\begingroup\$

I'm dropping a simple box onto a plane from 100 units and my solution using Bullet Physics is giving me some weird behavior. The dimensions of the box are {2, 4, 1}.

When the box hits the ground it jiggles up and down, drifts off to the side, and finally settles by sinking 1.5 units into the ground.

When I reduce the fall height to about 5 units the box doesn't sink into the ground, and the sideways drift is less pronounced.

When I declare a btSphereShape instead of a btBoxShape the problems go away. It should be noted that I'm developing for iOS with Objective-C file that interphases my code with Bullet.

Here's my code:

- (void)setUpPhysicsWorld { //This sets up the physics world and plane shape:

    collisionConfiguration = new btDefaultCollisionConfiguration();
    dispatcher = new btCollisionDispatcher(collisionConfiguration);
    broadphase = new btDbvtBroadphase();
    solver = new btSequentialImpulseConstraintSolver;
    dynamicWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);

    btTransform t;
    t.setIdentity();
    t.setOrigin(btVector3(0, 0, 0));
    btStaticPlaneShape *planeShape = new btStaticPlaneShape(btVector3(0, 1, 0), 0);
    btMotionState *motion = new btDefaultMotionState(t);
    btRigidBody::btRigidBodyConstructionInfo info(0.0, motion, planeShape);
    btRigidBody *planeRigidBody = new btRigidBody(info);
    dynamicWorld->addRigidBody(planeRigidBody);
    [self addBlock];

}

- (void)addBlock {

    btTransform t;
    t.setIdentity();
    t.setOrigin(btVector3(0, 5, 0));

    /* Actual declaration of the box shape. For some reason, when I change this
    to a btSphereShape, all the problems go away. */    
    btBoxShape *boxShape = new btBoxShape(btVector3(1, 2, 0.5)); 
    btVector3 inertia(0, 0, 0);
    boxShape->calculateLocalInertia(1.0, inertia);

    btMotionState *motion = new btDefaultMotionState(t);
    btRigidBody::btRigidBodyConstructionInfo info(1.0, motion, boxShape, inertia);
    blockRigidBody = new btRigidBody(info);
    dynamicWorld->addRigidBody(blockRigidBody);

}

- (GLKVector3)getBLockLocation {

    dynamicWorld->stepSimulation(1/60.f, 10, 1/300.0);

    btTransform trans;
    blockRigidBody->getMotionState()->getWorldTransform(trans);

    return GLKVector3Make(trans.getOrigin().getX(), trans.getOrigin().getY(), trans.getOrigin().getZ());

}

Can anyone tell me what's wrong here?

\$\endgroup\$
1
  • \$\begingroup\$ Nobody wants to help me? Please, somebody! \$\endgroup\$
    – Adil Patel
    Aug 22, 2013 at 10:01

1 Answer 1

1
\$\begingroup\$

Maybe try giving the objects and/or the plane some friction:

btRigidBody::btRigidBodyConstructionInfo info(1.0, motion, boxShape, inertia);
info.m_friction = 0.9f;
blockRigidBody = new btRigidBody(info);
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .