Make character not collide with btGhostObject

Mind Calamity
Posts: 13
Joined: Tue Feb 28, 2012 7:51 am

Make character not collide with btGhostObject

Post by Mind Calamity »

I'm having a bit of trouble making a proper trigger, I setup my trigger and character ghost objects like this:

Code: Select all

	{
		btTransform trans;
		trans.setIdentity();
		trans.setOrigin(btVector3(25, 0, 0));
		btSphereShape* shape = new btSphereShape(10.0f);

		mTriggerObj = new btPairCachingGhostObject();
		mTriggerObj->setWorldTransform(trans);
		mTriggerObj->setCollisionShape(shape);
		mTriggerObj->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE);
		mScene->addCollisionObject(mTriggerObj, btBroadphaseProxy::SensorTrigger, btBroadphaseProxy::AllFilter & ~btBroadphaseProxy::StaticFilter & ~btBroadphaseProxy::SensorTrigger);
	}
and character:

Code: Select all

	mGhostObj = new btPairCachingGhostObject();
	mGhostObj->setWorldTransform(startTransform);
	btScalar characterHeight=1.75;
	btScalar characterWidth = mSceneMgr->getEntity("Char")->getBoundingRadius();
	btConvexShape* capsule = new btCapsuleShape(characterWidth,characterHeight);
	mGhostObj->setCollisionShape (capsule);
	mGhostObj->setCollisionFlags (btCollisionObject::CF_CHARACTER_OBJECT);
	mScene->addCollisionObject(mGhostObj, btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter | btBroadphaseProxy::SensorTrigger | btBroadphaseProxy::DefaultFilter);
The trigger ghost object doesn't collide with rigid bodies, and I can retrieve the bodies inside it, but the character still collides and only reports hits if I walk directly towards the trigger sphere.

Basically I want the character and rigid bodies to not collide, but I want to still be able to get the bodies inside the ghost object.

Here's how I'm trying to get the bodies inside: (adapted from the wiki)

Code: Select all

	btManifoldArray   manifoldArray;
	btBroadphasePairArray& pairArray = mTriggerObj->getOverlappingPairCache()->getOverlappingPairArray();
	int numPairs = pairArray.size();

	for (int i=0;i<numPairs;i++)
	{
		manifoldArray.clear();

		const btBroadphasePair& pair = pairArray[i];

		//unless we manually perform collision detection on this pair, the contacts are in the dynamics world paircache:
		btBroadphasePair* collisionPair = mScene->getPairCache()->findPair(pair.m_pProxy0,pair.m_pProxy1);
		if (!collisionPair)
			continue;

		if (collisionPair->m_algorithm)
			collisionPair->m_algorithm->getAllContactManifolds(manifoldArray);

		for (int j=0;j<manifoldArray.size();j++)
		{
			btPersistentManifold* manifold = manifoldArray[j];
			btScalar directionSign = manifold->getBody0() == mTriggerObj ? btScalar(-1.0) : btScalar(1.0);
			for (int p=0;p<manifold->getNumContacts();p++)
			{
				const btManifoldPoint&pt = manifold->getContactPoint(p);
				if (pt.getDistance()<0.f)
				{
					const btVector3& ptA = pt.getPositionWorldOnA();
					const btVector3& ptB = pt.getPositionWorldOnB();
					const btVector3& normalOnB = pt.m_normalWorldOnB;
					/// work here
					Ogre::Vector3 pos = BtOgre::Convert::toOgre(ptB);
					printf("Hit at %s\n", Ogre::StringConverter::toString(pos).c_str());
				}
			}
		}
	}
gman0
Posts: 1
Joined: Fri Sep 02, 2011 9:34 pm

Re: Make character not collide with btGhostObject

Post by gman0 »

Hi,

I had this exact problem - the solution is quite simple:

(I guess you're using some of the bullet's character controller code)

Last time I checked the btKinematicClosestNotMeConvexResultCallback::addSingleResult method doesn't check for hasContactRespone() so you should add this in there:

Code: Select all

	if (convexResult.m_hitCollisionObject == m_me ||
		!convexResult.m_hitCollisionObject->hasContactResponse())
		return 1.0;
which nicely stops the collision from being resolved. And also in your penetartion-recovery method's main loop:

Code: Select all

		// Does the other object respone?
		if (!((btCollisionObject*)collisionPair->m_pProxy0->m_clientObject)->hasContactResponse() ||
			!((btCollisionObject*)collisionPair->m_pProxy1->m_clientObject)->hasContactResponse())
			continue;
This might be helpful (most of the code is from bullet's cc): https://github.com/gman0/Quarter-Life/b ... hysics.cpp
Mind Calamity
Posts: 13
Joined: Tue Feb 28, 2012 7:51 am

Re: Make character not collide with btGhostObject

Post by Mind Calamity »

I actually ran into your tutorial a few days ago but skipped it, since btKinematicCharacter did most of what I needed, but because of this problem and me being too lazy to re-compile bullet, I adapter your code, and it worked great. :)

Thanks a lot, and you might want to update your code on that page. :)