# Bullet physics weird behavior. Jittering and drifting with btBoxShape

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);
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);

}

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);

}

- (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?

• Nobody wants to help me? Please, somebody! Aug 22 '13 at 10:01

btRigidBody::btRigidBodyConstructionInfo info(1.0, motion, boxShape, inertia);