Capsule collider orientation with btKinematicCharacterController

Post Reply
sun_stealer
Posts: 1
Joined: Wed Jul 29, 2020 10:57 am

Capsule collider orientation with btKinematicCharacterController

Post by sun_stealer »

Maybe I am missing something, but it seems like Bullet (just like 3D rendering engine I'm using) uses Y-up coordinate frame.
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());
Screenshot from 2020-07-29 04-03-46.png
Screenshot from 2020-07-29 04-03-46.png (19.34 KiB) Viewed 16209 times
Post Reply