Changing collision filter flags on the fly

Post Reply
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm
Contact:

Changing collision filter flags on the fly

Post by dphil »

I'm familiar with the tutorial on filtering collisions using bitmasks -->http://bulletphysics.org/mediawiki-1.5. ... _Filtering. In everything I have seen, it's always done when an object is set up and inserted into the collision world. But what if I want to change these masks on the fly, once the simulation is already running? Can I grab a reference to a collision object and modify its collision group and/or mask?

I saw some semi-related code in another thread that seemed to imply that to do this one must remove the object from the collision world and then re-add it with the newly desired collision group and mask values.

Ie.

Code: Select all

world->removeCollisionObject(collObj);
world->addCollisionObject(collObj, newFilterGroup, newFilterMask);
... // any other code to awaken/reactivate object
Is this basically how it is done, or is there a preferred method for updating collision filtering on the fly? I imagine I could perhaps use one of the callback methods also described in the tutorial, but the bitmask method seems more ideal and simpler.
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm
Contact:

Re: Changing collision filter flags on the fly

Post by dphil »

I ended up just removing and re-adding the body with the new collision masks. This seems to be the way to do it, and it works.
nictosi
Posts: 11
Joined: Mon Jul 06, 2015 9:25 am

Re: Changing collision filter flags on the fly

Post by nictosi »

Thanks for posting the reply. I have the same problem and it removing and adding the object with modified mask seems to do the trick. I guess there is some performance loss in changing the mask though.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Changing collision filter flags on the fly

Post by benelot »

I think there is currently no other way to do it based on bit masks, so that is your solution. Alternatively, you could implement custom collision filtering from the article you mention and change it according to your needs.

If you like your solution, mark the thread as solved by editing the top post's title and adding [SOLVED] to the beginning.
Post Reply