Sign in to follow this  

btKinematicCharacterController Not Behaving Correctly

Recommended Posts

So I've been trying to add in a character controller in my game by using btKinematicCharacterController. I had some working code from another project that used Bullet, so I'm mostly relying off of that because there isn't a whole lot of documentation for btKinematicCharacterController. For some reason whenever I add it into the world with only a static plane as the other collider, it flies off in the negative x-direction and is not effected by gravity. 

 

Here is the code for creating the physics world:

// Create the necessary components for a bullet physics world
    bullet_broadphase = new btDbvtBroadphase();
    
    bullet_collision_configuration = new btDefaultCollisionConfiguration();
    bullet_collision_dispatcher = new btCollisionDispatcher(bullet_collision_configuration);
    
    bullet_constraint_solver = new btSequentialImpulseConstraintSolver();
    
    // Create the bullet world
    bullet_world = new btDiscreteDynamicsWorld(bullet_collision_dispatcher,
                                               bullet_broadphase,
                                               bullet_constraint_solver,
                                               bullet_collision_configuration);
    
    // Set gravity, by default it is -9.8 m/s in the y direction
    bullet_world->setGravity(btVector3(0.0, -9.8, 0.0));

Here is the code for the creation of my character controller and its ghost body (collision_shape is a capsule with radius 0.5 and height 1.0)

// Create a ghost object
    ghost_body = new btPairCachingGhostObject();
    moveControllerToParent(0.0);
    ghost_body->setCollisionShape(collision_shape);
    ghost_body->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);
    
    // Create the character controller
    controller = new btKinematicCharacterController(ghost_body, collision_shape, btScalar(0.1));
    controller->setUseGhostSweepTest(false);
    
    // Only listen to post-physics tick
    event_listener.listenToEvent(EVENT_PHYSICS_POSTUPDATE, EVENT_MEMBER(SPhysicsController::postPhysicsUpdate));

And then my code to add it to the world

// Add the controller's components to the world
    bullet_world->addCollisionObject(ghost_body, btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter);
    bullet_world->addAction(controller);

Does anyone have any ideas as to why this isn't working? When the btKinematicCharacterController isn't attached to the ghost body, it doesnt seem to have any issues. If anyone has any ideas as to why this is happening it would be much appreciated. Thanks.

 

EDIT: Apparently in a new update character controllers were given their own gravity, so after updating that the character controller behaves correctly, however it not interpolating smoothly. 

Edited by BlueSpud

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this