I followed some demos online and created a btKinematicCharacterController object, but DebugDraw shows that the capsule is aligned with a horizontal rather than vertical axis, even though it's supposed to be upright according to the documentation.
Using btCapsuleShapeZ instead of btCapsuleShape seems to fix the issue, but it seems like a hack.
Is this caused by the wrong orientation of the ghost object?
In general, I am struggling a lot with btKinematicCharacterController. I know it is not supported, but does anyone have a working demo with a character controller driven by Bullet? Can you give me general advice on how to get something working without writing an FPS controller from scratch?
Below is the code that I currently use to create the character:
Code: Select all
btTransform startTransform;
startTransform.setIdentity ();
startTransform.setOrigin (btVector3(1.5, 12.0, 0.5));
ghostObject.setWorldTransform(startTransform);
btScalar characterHeight = 1.75;
btScalar characterWidth = 0.5;
capsuleShape = std::make_unique<btCapsuleShape>(characterWidth, characterHeight);
ghostObject.setCollisionShape(capsuleShape.get());
ghostObject.setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);
auto stepHeight = btScalar(0.35);
bCharacter = std::make_unique<btKinematicCharacterController>(&ghostObject, capsuleShape.get(), stepHeight, btVector3(0.0, 1.0, 0.0));
bCharacter->setGravity(btVector3(0, -9.8f, 0));
bWorld.addCollisionObject(&ghostObject, btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
bWorld.addAction(bCharacter.get());