trouble with deactivate/activate of collision objects

jackrwright
Posts: 3
Joined: Fri Jul 24, 2009 12:07 pm

trouble with deactivate/activate of collision objects

Post by jackrwright »

I'm trying to use these functions to deactivate/activate collision objects, but the simulation doesn't behave well for a time after activating objects...

to deactivate an object:

Code: Select all

	m_savedCollisionGroup = m_rigidBody->getBroadphaseHandle()->m_collisionFilterGroup;
	m_savedCollisionMask = m_rigidBody->getBroadphaseHandle()->m_collisionFilterMask;

	m_rigidBody->forceActivationState(DISABLE_SIMULATION);

	m_rigidBody->getBroadphaseHandle()->m_collisionFilterGroup = 0;
	m_rigidBody->getBroadphaseHandle()->m_collisionFilterMask = 0;
to activate:

Code: Select all

	m_rigidBody->forceActivationState(DISABLE_DEACTIVATION);

	m_rigidBody->getBroadphaseHandle()->m_collisionFilterGroup = m_savedCollisionGroup;
	m_rigidBody->getBroadphaseHandle()->m_collisionFilterMask = m_savedCollisionMask;
The trouble is that some objects pass through each other without colliding for a while. Then after a few seconds, they suddenly start colliding. The collisions seem to be detected, since my collision callback is called, but the objects don't react to the collisions.

Is there something else I must do to tell the simulation about the new states?
kate
Posts: 41
Joined: Thu Jan 08, 2009 11:20 am
Location: London, UK

Re: trouble with deactivate/activate of collision objects

Post by kate »

Hey,

Is there a reason why you don't just remove the rigid bodies from the world, then re-add them?

(I had a similar problem a while ago when implementing collision masks, as I was just setting the collision filter group/mask data directly, and found that removing and re-adding the objects was the easiest way to get the collisions to recompute and behave properly).

Regards,

Kate
jackrwright
Posts: 3
Joined: Fri Jul 24, 2009 12:07 pm

Re: trouble with deactivate/activate of collision objects

Post by jackrwright »

Kate,

I thought it would be more efficient to activate/deactivate. I've also had trouble re-adding them, but I may be missing something (I'm new to bullet).

When I tried the re-add technique, The added objects would sometimes suddenly change velocity.

remove:

Code: Select all

	sDynamicsWorld->removeRigidBody(m_rigidBody);
add:

Code: Select all

	m_rigidBody->setLinearVelocity(_velocity);

	sDynamicsWorld->addRigidBody(m_rigidBody, m_savedCollisionGroup, m_savedCollisionMask);
Maybe there's something else I need to re-init in the rigid body before adding it back.

Jack
kate wrote:Hey,

Is there a reason why you don't just remove the rigid bodies from the world, then re-add them?

(I had a similar problem a while ago when implementing collision masks, as I was just setting the collision filter group/mask data directly, and found that removing and re-adding the objects was the easiest way to get the collisions to recompute and behave properly).

Regards,

Kate
jackrwright
Posts: 3
Joined: Fri Jul 24, 2009 12:07 pm

Re: trouble with deactivate/activate of collision objects

Post by jackrwright »

I may have solved the problem. I also had constraints on the objects, but I was was not removing them from the simulation when I removed the rigid body.

Once I also removed the constraint with the rigid body, and then added both the rigid body and the constraint back, the collisions have so far been acting normally.

Jack