I am working on a project for university and decided to use the bullet physics engine.
I'm trying to implement a btKinematicCharacterController for my test player class but I've encountered multiple problems of which I don't even know where to begin to look.
Problem 1:
No acceleration on gravity. Just floats down to the surface at a steady velocity.
Problem 2:
Doesn't "jump()".
When debugging I found that the character is never "onGround()".
When visually on ground, m_verticalVelocity and the m_verticalOffset are always less than 0. This means that I cannot call the jump command because the "onGround()" function never returns true.
(approx values are -55.3 and -9.8 respectively).
My code for setting up the kinematic character is:
Code: Select all
bool addToPhysicsWorld(PhysicsWorld* pw)
{
if (!pw)
return false;
btVector3 worldMin(-1000,-1000,-1000);
btVector3 worldMax(1000,1000,1000);
btTransform startTransform;
startTransform.setIdentity ();
startTransform.setOrigin (btVector3(668,706,7)); //Place it in the middle of a map (currently testing on: q3dm1.bsp)
double sq05 = sqrt(0.5);
startTransform.setRotation( btQuaternion(sq05,0,0,sq05) ); //Rotate the shape because Z axis is up.
mp_ghostObject = new btPairCachingGhostObject();
mp_ghostObject->setWorldTransform(startTransform);
characterHeight = 40;
characterWidth = 20;
btConvexShape* capsule = new btCapsuleShape(characterWidth,characterHeight);
mp_ghostObject->setCollisionShape (capsule);
mp_ghostObject->setCollisionFlags (btCollisionObject::CF_CHARACTER_OBJECT);
btScalar stepHeight = btScalar(0.35);
mp_character = new btKinematicCharacterController(mp_ghostObject,capsule,stepHeight,2);
mp_character->setFallSpeed( 1000 );
mp_character->setGravity( 10 );
pw->getDynamicsWorld()->addCollisionObject(mp_ghostObject,btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
pw->getDynamicsWorld()->addAction(mp_character);
m_colOffsetZ = characterHeight/2 + 20; //Used for model placement.
return true;
}
Any thoughts, tips, pointers or solutions out there?