Crash when CharacterController collides with static plane

Post Reply
Kukanani
Posts: 25
Joined: Sat Feb 21, 2009 5:08 am

Crash when CharacterController collides with static plane

Post by Kukanani »

Hi,

I'm setting up a character controller in my Bullet/Ogre application. Currently I'm starting the character 50 meters above the ground for various debugging purposes. As the character falls towards the ground, everything is fine. But the instant the character hits the static plane I'm using as a floor, the application crashes. I've managed to pinpoint the problem to a single line of code, dynamicsWorld->stepSimulation, right when the ghost object capsule hits the static plane.

Code:

Code: Select all

void setup() {
//...
	ghostObject = new btPairCachingGhostObject();
	ghostObject->setWorldTransform(btTransform(btQuaternion().getIdentity(), btVector3(x, y, z)));
	broadphase->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());

	btConvexShape* capsule = new btCapsuleShape(.8f, 1.8f);
	ghostObject->setCollisionShape(capsule);
	ghostObject->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);

	character = new btKinematicCharacterController(ghostObject,capsule,0.35f);

	dynamicsWorld->addCollisionObject(ghostObject,btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);

	dynamicsWorld->addAction(character);
        //...
}

void update() {
    //...
    dynamicsWorld->stepSimulation(((float)elapsedTime)/1000.f); <<<<<<<<<<< this line causes the crash
    dynamicsWorld->debugDrawWorld();

    	btVector3 o = ghostObject->getWorldTransform().getOrigin();
	float x = o.x();
	float y = o.y();
	float z = o.z();
	ogreCharacter->setPosition(x, y, z);
    //...
}

What is wrong? Is there a bug in btKinematicCharacterController?

Thanks,
Kukanani
Kukanani
Posts: 25
Joined: Sat Feb 21, 2009 5:08 am

Re: Crash when CharacterController collides with static plane

Post by Kukanani »

Alright, now I'm really weirded out. If I use a static cube instead of a static plane, it works fine.

For now I have no problem using a plane instead of a cube, but I still don't understand why a btStaticPlaneShape doesn't work. Can someone tell me?
Kukanani
Posts: 25
Joined: Sat Feb 21, 2009 5:08 am

Re: Crash when CharacterController collides with static plane

Post by Kukanani »

Here's another thing: the app crashes when a CharacterController collides with a btHeightfieldTerrainShape:

Code: Select all

	btHeightfieldTerrainShape* heightfieldShape = new btHeightfieldTerrainShape(50, 50, terrain->getHeightData(), 1, 0, 20, 1, PHY_FLOAT, false);
	heightfieldShape->setLocalScaling(btVector3(1000.f/512.f, 1, 1000.f/512.f));

	heightfieldShape->calculateLocalInertia(0.f, localInertia);

	btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btMatrix3x3().getIdentity(), btVector3(0.f, 15.f, 0.f)));

	btRigidBody* body = new btRigidBody(0.f, motionState, heightfieldShape, localInertia);

    //add the body to the dynamics world
    dynamicsWorld->addRigidBody(body);

Code: Select all

	btTransform startTransform;
	startTransform.setIdentity();
	startTransform.setOrigin(btVector3(x, y, z));

	ghostObject = new btPairCachingGhostObject();
	ghostObject->setWorldTransform(startTransform);
	((btAxisSweep3*)dynamicsWorld->getBroadphase())->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());

	btScalar width = 0.6f;
	btScalar height = 0.4f;
	btConvexShape* capsule = new btCapsuleShape(width, height);

	ghostObject->setCollisionShape(capsule);
	ghostObject->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);

	btScalar stepSize = 0.2f;
	character = new btKinematicCharacterController(ghostObject,capsule,stepSize);

	dynamicsWorld->addCollisionObject(ghostObject,btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
	dynamicsWorld->addAction(character);
The application still crashes in dynamicsWorld->stepSimulation, just after the character hits the terrain.

Please, please, will someone tell me what is wrong with my code? This is a ridiculous problem, most of my code is grabbed right out of the demos and it still doesn't work.
monah
Posts: 8
Joined: Thu Nov 19, 2009 1:05 pm

Re: Crash when CharacterController collides with static plan

Post by monah »

I also get a crash collision CharacterController with btheightfieldterrainshape. Revision 2050 works well, head revision I get crash. Someone can help fix this error?
Vroonsh
Posts: 5
Joined: Wed Mar 17, 2010 4:09 pm

Re: Crash when CharacterController collides with static plan

Post by Vroonsh »

Hi,

I've had the same issue with a rigid boy falling or simply touching the Character in appCharacterDemo several monthes ago.

I solved that by adding CF_KINEMATIC_OBJECT to the ghostobject collision flags.

m_ghostObject->setCollisionFlags (btCollisionObject::CF_CHARACTER_OBJECT | btCollisionObject::CF_KINEMATIC_OBJECT);

Maybe it could solve your problem.

Regards

Boris
Post Reply