Kinematic Character Controller Falling Through the Floor

debio264

10-11-2009 21:14:19

I'm trying to get a Kinematic Character Controller working, and it doesn't seem to be colliding with anything. It just falls through the floor as soon as it spawns.
Here's the code where I set it up:
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0.0, 50.0, -0.0));

btPairCachingGhostObject* m_ghostObject = new btPairCachingGhostObject();
m_ghostObject->setWorldTransform(startTransform);
btScalar characterHeight = 1.75;
btScalar characterWidth = 1.0;
btConvexShape* capsule =
new btCapsuleShape(characterWidth, characterHeight);
m_ghostObject->setCollisionShape(capsule);
m_ghostObject->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);
btScalar stepHeight = btScalar(0.35);
btKinematicCharacterController* m_character =
new btKinematicCharacterController(m_ghostObject, capsule,
stepHeight);
oWorld->getBulletDynamicsWorld()->addCollisionObject(m_ghostObject,
btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::AllFilter);
oWorld->getBulletDynamicsWorld()->addAction(m_character);


This is mostly just the Kinematic Character Controller demo code, so I think my problem must be in how I add it to the world because I'm bypassing OgreBullet, and there's probably something I haven't thought of that's causing issues. Here's how I create the floor:
Ogre::Plane plane;
plane.normal = Ogre::Vector3::UNIT_Y;
plane.d = 100;

Ogre::MeshManager::getSingleton().createPlane("planeMesh",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
1500, 1500, 20, 20, true, 1, 60, 60, Ogre::Vector3::UNIT_Z);

...

OgreBulletCollisions::StaticMeshToShapeConverter *trimeshConverter =
new OgreBulletCollisions::StaticMeshToShapeConverter(planeEnt);
OgreBulletCollisions::TriangleMeshCollisionShape *sceneTriMeshShape =
trimeshConverter->createTrimesh();
delete trimeshConverter;
OgreBulletDynamics::DynamicsWorld *oWorld =
new OgreBulletDynamics::DynamicsWorld(sceneMgr,
Ogre::AxisAlignedBox(Ogre::Vector3(-1500, -1500, -1500),
Ogre::Vector3(1500, 1500, 1500)), Ogre::Vector3(0,
-9.8, 0));
OgreBulletDynamics::RigidBody *planeRigid =
new OgreBulletDynamics::RigidBody("planeRigid", oWorld);
planeRigid->setStaticShape(planeNode, sceneTriMeshShape, 0.0f, 0.8f);


Once again, this is mostly code reuse. I try to avoid being original until I've got something working, and I'm fairly new to this as well.
Am I doing something wrong? Am I doing everything wrong?

debio264

11-11-2009 00:27:53

Well, I managed to figure it out. I needed to add "oWorld->getBulletDynamicsWorld()->getPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());" so Bullet would correctly handle collisions involving a ghost object.