I am testing out Bullet's capabilities and liking it so far! I do have a problem with the character controller.
I have used the code from the character demo as a guideline and created the character and capsule. In addition to that i have a btStaticPlaneShape in my scene. Now if i understand correctly, the character will fall down until it hits this plane. After that i should be able to move the character around.
But that doesn't happen! The character just falls down, i even tried to set the gravity to (0,0,0) and it would still fall down endlessly. What is it i am forgetting? Here is the code for the creation of the plane and character:
Code: Select all
{
std::fstream file_op("c:\\test_file.txt", std::ios::out);
btVector3 worldAabbMin(-10000,-10000,-10000);
btVector3 worldAabbMax(10000,10000,10000);
int maxProxies = 1024;
btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,-10,0));
btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
btRigidBody::btRigidBodyConstructionInfo
groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
dynamicsWorld->addRigidBody(groundRigidBody);
btKinematicCharacterController* m_character;
btPairCachingGhostObject* m_ghostObject;
btVector3 worldMin(-10000,-10000,-10000);
btVector3 worldMax(10000,10000,10000);
btAxisSweep3* sweepBP = new btAxisSweep3(worldMin,worldMax);
{
btTransform startTransform;
startTransform.setIdentity ();
startTransform.setOrigin (btVector3(0.0, 20.0, 0.0));
m_ghostObject = new btPairCachingGhostObject();
m_ghostObject->setWorldTransform(startTransform);
sweepBP->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
btScalar characterHeight=1.75;
btScalar characterWidth =1.75;
btConvexShape* capsule = new btCapsuleShape(characterWidth,characterHeight);
m_ghostObject->setCollisionShape (capsule);
m_ghostObject->setCollisionFlags (btCollisionObject::CF_CHARACTER_OBJECT);
btScalar stepHeight = btScalar(0.35);
m_character = new btKinematicCharacterController (m_ghostObject,capsule,stepHeight);
///only collide with static for now (no interaction with dynamic objects)
dynamicsWorld->addCollisionObject(m_ghostObject);
dynamicsWorld->addCharacter(m_character);
}
float y = 0;
for (int i=0 ; i<3000 ; i++) {
dynamicsWorld->stepSimulation(1/60.f,10);
btTransform trans = m_ghostObject->getWorldTransform();
y = trans.getOrigin().getY();
file_op << "Capsule height: " << y << std::endl;
}
file_op.close();
}
Code: Select all
Capsule height: 19.3
Capsule height: 18.95
Capsule height: 18.6
Capsule height: 18.25
Capsule height: 17.9
Capsule height: 17.55
Capsule height: 17.2
Capsule height: 16.85
Capsule height: 16.5
Capsule height: 16.15
Capsule height: 15.8
Capsule height: 15.45
Capsule height: 15.1
Capsule height: 14.75
Capsule height: 14.4
Capsule height: 14.05
Capsule height: 13.7
Capsule height: 13.35
Capsule height: 13
Capsule height: 12.65
Capsule height: 12.3
Capsule height: 11.95
Capsule height: 11.6
Capsule height: 11.25
Capsule height: 10.9
Capsule height: 10.55
Capsule height: 10.2
Capsule height: 9.85001
Capsule height: 9.50001
Capsule height: 9.15001
Capsule height: 8.80001
Capsule height: 8.45001
Capsule height: 8.10001
Capsule height: 7.75001
Capsule height: 7.40001
Capsule height: 7.05001
Capsule height: 6.70001
Capsule height: 6.35001
Capsule height: 6.00001
Capsule height: 5.65001
Capsule height: 5.30001
Capsule height: 4.95001
Capsule height: 4.60001
Capsule height: 4.25001
Capsule height: 3.90001
Capsule height: 3.55001
Capsule height: 3.20001
Capsule height: 2.85001
Capsule height: 2.50001
Capsule height: 2.15001
Capsule height: 1.80001
Capsule height: 1.45001
Capsule height: 1.10001
Capsule height: 0.750009
Capsule height: 0.400009
Capsule height: 0.0500092
Capsule height: -0.299991
Capsule height: -0.649991
Capsule height: -0.999991
Capsule height: -1.34999
Capsule height: -1.69999
Capsule height: -2.04999
Capsule height: -2.39999
Capsule height: -2.74999
Capsule height: -3.09999
Capsule height: -3.44999