For now I have a simple game where the character pushes boxes around (basically Sokoban in 3D), however the boxes can sometimes be pushed into the wall, when the character backs off they will pop out again.
I have setAngularFactor(0.0) set on the boxes to stop them rotating, and the walls are RigidBodies with a mass of 0, so they are exactly flat on to each other.
Theres a lot of code so I can't really post it here.
This is my main update loop function called from my game (the time is SDL_GetTicks() rather than the bullet one, I don't know if thats likely to case anything odd.). I'm not too sure if this is the best way to update it, ive seen posts talking about fixed frequency ones and I can see that the physics outcome might be based on the framerate.
Code: Select all
/**
* updates the physics based on the time.
* @param time The current game time in milliseconds.
*/
void Physics::update(const int time) {
int time_diff = time - getLastupdate();
if(time_diff <= 0) {
return;
}
btScalar timeStep = ((float)time_diff) / 1000.0f;
int numsimsteps = dynamicsWorld_->stepSimulation(timeStep,0,1.0/60.0);
Updateable::update(time); // Just sets the value for getLastUpdate.
}
Code: Select all
Physics::Physics() {
body_max_ = 16384; /* Maximum number of rigid bodies */
btVector3 worldAabbMin(-10000,-10000,-10000);
btVector3 worldAabbMax(10000,10000,10000);
broadphase_ = new btAxisSweep3(worldAabbMin,worldAabbMax,body_max_);
collisionConfiguration_ = new btDefaultCollisionConfiguration();
dispatcher_ = new btCollisionDispatcher(collisionConfiguration_);
solver_ = new btSequentialImpulseConstraintSolver;
dynamicsWorld_ = new btDiscreteDynamicsWorld(dispatcher_,
broadphase_, solver_, collisionConfiguration_);
setGravity(GRAVITY_EARTH);
gDebugDrawer_.setDebugMode(1);
dynamicsWorld_->setDebugDrawer(&gDebugDrawer_);
body_count_ = 0;
}