problems with btKinematicCharacterController

Magusware
Posts: 2
Joined: Mon Oct 24, 2011 9:14 pm

problems with btKinematicCharacterController

Post by Magusware »

Hello Bullet forums.

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?
dumbo2007
Posts: 66
Joined: Sun Jan 30, 2011 8:46 pm

Re: problems with btKinematicCharacterController

Post by dumbo2007 »

You do set a gravity for the dynamics world object too , right ?
Magusware
Posts: 2
Joined: Mon Oct 24, 2011 9:14 pm

Re: problems with btKinematicCharacterController

Post by Magusware »

I do yeah, but from what I understand, this kinematic character controller uses it's own gravity setting right?

During some more tests I noticed something else.

onGround DOES get called eventually, when the origin of the kinematic character controller is on the ground, so visually, it would appear half in / half out the ground. Only then does onGround return true.
I noticed this by leaving it for a while, watching the character slowly sink into the ground, and eventually stopped moving. Then I pressed space and a break point I placed in the jump got triggered, which would only be reached if on ground.

It's bizzare because the the character falls at x speed then when it touches the ground it continues to fall but at a slower rate. very confusing.
Martin Felis
Posts: 13
Joined: Sat Oct 29, 2011 9:32 pm

Re: problems with btKinematicCharacterController

Post by Martin Felis »

Concerning problem 1) it seems to me that your gravity might not fit to the units of your other values. At least character height and gravity do not seam to be properly related. Assuming you were using meters, then the character would be 40m high but still only have 10 m/s^2 acceleration downwards. Maybe you get better results in drastically increasing the gravity magnitude?