Problem with btPairCachinGhostObject

User avatar
trigger-happy
Posts: 4
Joined: Thu Jun 30, 2011 11:12 am

Problem with btPairCachinGhostObject

Post by trigger-happy »

Hi, I'm using bullet right now for a game I'm developing and I've run into a little problem while using byPairCahingGhostObject for my map triggers. The triggers sort of work in that they detect collisions with my character, but the problem is that they act like solid objects and refuse to let the character pass through. I've spent quite a bit of time trying to toy with collision flags and still to no avail. Help on solving this issue would be very much appreciated.

Here's my constructor code for the trigger object:

Code: Select all

MapTrigger::MapTrigger(
    OgreBulletCollisions::CollisionShape* shape,
    OgreBulletDynamics::DynamicsWorld* world,
    Ogre::SceneNode* sn,
    bool active,
    bool visible
)
	: m_sn( sn ), m_shape( shape ), m_world( world ), m_active( active ), m_visible( visible )
{
	if( m_sn ) {
		btTransform xform;
		xform.setOrigin( obc::OgreBtConverter::to( sn->getPosition() ) );
		xform.setRotation(obc::OgreBtConverter::to(sn->getOrientation().Inverse()));

		m_ghostobj = new btPairCachingGhostObject();
		m_ghostobj->setWorldTransform( xform );
		m_ghostobj->setCollisionShape( shape->getBulletShape() );
		m_ghostobj->setCollisionFlags(
		    m_ghostobj->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE
		);
		
		m_world->getBulletDynamicsWorld()->addCollisionObject(
		    m_ghostobj, btBroadphaseProxy::SensorTrigger, btBroadphaseProxy::CharacterFilter
		);
	}
}
This is for my character object

Code: Select all

ActorController::ActorController( obd::DynamicsWorld* w,
                                  Ogre::SceneNode* sn,
                                  ActorConfig cfg,
                                  CONTROL_SCHEME cs
                                )
{
	m_world = w;
	// note that we are passed the scenenode that contains the entity
	m_ent_node = sn;
	m_sm = NULL;
	m_cfg = cfg;
	m_move_rate = m_cfg.max_speed;
	m_controlscheme = cs;
	m_rts_movement = MOVE_STOP;
	m_turn_state = TURN_NONE;
	m_as_movement = 0;
	m_movement_direction = btVector3( 0, 0, 0 );


	if( sn ) {
		// m_controlled_node is actually Ogre::SceneNode that pertains to object position
		// it MUST NOT rotate, EVER
		m_controlled_node = sn->getParentSceneNode();
		o::String name = m_controlled_node->getName();
		// create the sight node scenenodes
		o::Vector3 temp( 0, 0, c_look_forward_offset );
		m_sight_node = m_controlled_node->createChildSceneNode(
		                   name + "_sight", temp
		               );

		// create the chase cam node
		temp = o::Vector3( c_cam_x_offset, c_cam_y_offset, c_cam_z_offset );
		m_camera_node = m_controlled_node->createChildSceneNode(
		                    name + "_camera", temp
		                );

		m_weapon_node = reinterpret_cast<o::SceneNode*>( m_controlled_node->getChild( "weapon_holder" ) );

		m_sm = sn->getCreator();
		btTransform startpos;
		startpos.setIdentity();
		btVector3 sp = obc::OgreBtConverter::to( sn->getPosition() );
		btQuaternion qp = obc::OgreBtConverter::to( sn->getOrientation().Inverse );
		startpos.setOrigin( sp );
		startpos.setRotation( qp );

		m_ghost_object = new btPairCachingGhostObject();
		m_ghost_object->setWorldTransform( startpos );

		btConvexShape* capsule = new btCapsuleShape(
		    cfg.character_width, cfg.character_height
		);
		m_ghost_object->setCollisionShape( capsule );
		m_ghost_object->setCollisionFlags( btCollisionObject::CF_CHARACTER_OBJECT );
		m_character = new btKinematicCharacterController(
		    m_ghost_object, capsule, m_cfg.max_step_height
		);

		m_world->getBulletDynamicsWorld()->addCollisionObject(
		    m_ghost_object, btBroadphaseProxy::CharacterFilter,
		    btBroadphaseProxy::AllFilter
		);
		m_world->getBulletDynamicsWorld()->addAction( m_character );

		xf = &( m_ghost_object->getWorldTransform() );
	}
}
Ask away if there's anything in the code that needs clarification.
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Problem with btPairCachinGhostObject

Post by dphil »

Hm, try:

Code: Select all

m_ghostobj->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE);
for the map triggers instead of

Code: Select all

m_ghostobj->setCollisionFlags(m_ghostobj->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
User avatar
trigger-happy
Posts: 4
Joined: Thu Jun 30, 2011 11:12 am

Re: Problem with btPairCachinGhostObject

Post by trigger-happy »

I tried that but the problem still persists, thanks for offering help on this though :)
User avatar
trigger-happy
Posts: 4
Joined: Thu Jun 30, 2011 11:12 am

Re: Problem with btPairCachinGhostObject

Post by trigger-happy »

*bump*
User avatar
trigger-happy
Posts: 4
Joined: Thu Jun 30, 2011 11:12 am

Re: Problem with btPairCachinGhostObject

Post by trigger-happy »

I've managed to resolve the issue myself by debugging the btKinematicCharacterController code found in bullet. The problem was that the controller was performing a collision response on its own without respecting the hasContactResponse of the object it's colliding with. This also happens with other objects, static or rigid body, that are suppose to have no contact response. Should I come up with a patch for the fix? And if yes, where do I submit it?