objects shot sky high when a btGhostObject is removed

paksas
Posts: 6
Joined: Wed Mar 18, 2009 8:55 am

objects shot sky high when a btGhostObject is removed

Post by paksas »

Hi

I've been browsing through the forum, but couldn't find a solution to a problem I've been dealing with for the past few days.

I have a bullet and a cannon that shoots it in the scene.
A cannon has a 'surveillance sphere' surrounding it that serves the purpose of detecting the approaching enemies.

When a cannon shoots a bullet, and that one hits a target INSIDE the 'surveillance sphere', the cannon gets shot sky high.

I modelled a bullet using a btGhostBody like so:

Code: Select all

btGhostBody* bullet = new btGhostBody();
bullet->setCollisionShape(new btBoxShape(btVector3(0.25, 0.25, 0.25)));
bullet->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE);
The cannon on the other hand is modelled using a btRigidBody (for the chassis) and the btGhostBody (for the surveillance sphere):

Code: Select all

btRigidBody* cannonChassis = new btRigidBody(0, cannonMotionState, 
                                                              new btBoxShape(btVector3(2, 2, 2)), 
                                                              btVector3(0, 0, 0));
cannonChassis->setCollisionFlags(btCollisionObject::CF_STATIC_OBJECT);

btGhostBody* surveillanceSphere = new btGhostBody();
surveillanceSphere->setCollisionShape(new btSphereShape(20));
surveillanceSphere->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE);

My scene is set up like so:

Code: Select all

btDefaultCollisionConfiguration*  collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btVector3 worldMin(-1000,-1000,-1000);
btVector3 worldMax(1000,1000,1000);
btAxisSweep3*  overlappingPairCache = new btAxisSweep3(worldMin, worldMax);
btSequentialImpulseConstraintSolver* constraintSolver = new btSequentialImpulseConstraintSolver();

btDiscreteDynamicsWorld* collisionWorld = new btDiscreteDynamicsWorld(dispatcher,
                                                  overlappingPairCache,
                                                  constraintSolver,
                                                  collisionConfiguration);

btVector3 gravity(0, -4, 0);
collisionWorld->setGravity(btVector3(gravity.x, gravity.y, gravity.z));

I remove the bullet from the scene like so:

Code: Select all

collisionWorld->removeCollisionObject(bullet);
And I use the following call to run the simulation:

Code: Select all

collisionWorld->stepSimulation(timeElapsed, 4)

Thank you very much in advance.

Cheerz,
Paksas