[Solved]Character capsule rotated in wrong axis

Please don't post Bullet support questions here, use the above forums instead.
Chase
Posts: 8
Joined: Tue Jan 18, 2011 7:14 pm

[Solved]Character capsule rotated in wrong axis

Post by Chase »

So I'm roughed it out with a few issues, but this one I'm just stuck on the proper method to handle it.

In my world, x and y are the vectors the player travels across and z is the height vector. The problem I get from this, is that when I create the btKinematicCharacterController's capsule shape, it's facing down the x and y axis, not the x and z. I can manually rotate the ghost object, but it messes up how the character controller see's the ground. I've also tried a combination of the controller's up axis as well as rotating, but that sent the character falling due to gravity in the wrong axis.

Below is the code I am using to set up the character...

Code: Select all

//Ghost Object
transform.setIdentity();
	
btPairCachingGhostObject* ghostObject = new btPairCachingGhostObject();
broadphase->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
ghostObject->setWorldTransform(transform);

//Capsule
btConvexShape* characterShape = new btCapsuleShape(0.5, 1.0);
ghostObject->setCollisionShape(characterShape);
ghostObject->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);
ghostObject->setFriction(1.0);

//Character controller
playerController = new btKinematicCharacterController(ghostObject, characterShape, 0.01, 2);

//Add collision object to world
dynamicsWorld->addCollisionObject(ghostObject,
         btBroadphaseProxy::CharacterFilter,
         btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter);

//Add controller to world
dynamicsWorld->addAction(playerController);
Last edited by Chase on Wed Jan 19, 2011 8:03 pm, edited 1 time in total.
Chase
Posts: 8
Joined: Tue Jan 18, 2011 7:14 pm

Re: [Solved Kinda]Character capsule rotated in wrong axis

Post by Chase »

So I was looking around inside of the btCapsuleShape class and I saw there is an upAxis variable, however there is no actual method to modify it. In my own code I changed the classes constructor to look like this...

Code: Select all

//Was this...
btCapsuleShape(btScalar radius,btScalar height);

//Now this....
btCapsuleShape(btScalar radius,btScalar height, int upAxis=1);
This simple change did everything I wanted, so in theory it works, but only by modifying core files. If there is a method I'm not seeing please let me know, otherwise this appears to be the only correct solution.
Chase
Posts: 8
Joined: Tue Jan 18, 2011 7:14 pm

Re: [Solved]Character capsule rotated in wrong axis

Post by Chase »

Upon further reveiw! I found there is a class called btCapsuleShapeZ which... just sets the axis to the z. I'm not really sure why this is separated as a different class, but at least it is there and I can use it without modification to the original source.