Temporarily turning off all collision on an object

Hey, gang!

Quick semi-noobish question for you. Let's say I've got a box2d project with a whole bunch of objects in 'em. And let's say that, for some reason, I want to temporarily have an object completely not interact with any object in the scene at all. For example, maybe I want to click-and-drag something around the scene without worrying about it colliding with bodies that are already there. What's the best way to do this?

Yeah, I know often the answer to these kinds of questions is to do some kind of collision filtering. But this seems like an exception in that a) I want to temporarily turn off and on the "collidability" of the object, and filtering seems to be designed for objects that don't change their collidability features mid-stream, b) I'm making the object not collide with anything in the world at all, instead of a subset of objects, and filtering in this case seems kinda overkill, and also c) I'm lazy, and don't really want to go back and add category bits and mask bits to every freakin' object in the scene.

Some solutions I've thought of are... a) Destroying the underlying physics body when I start dragging the object and then recreating again when I stop, b) Temporarily moving the underlying physics body to some far-off location and then bring it back again, or c) Bite the bullet and use filtering. But I guess I was hoping there was a more elegant solution than any of the ones I've considered so far.

Thoughts? Help me, Box2DFlash forum list! You're my only hope!
I'm new to box2d myself so not sure how much help I can be / whether this is just plain wrong.

But would changing the object to isSensor = true; for when you dont want it to physically collide with anything do the job?

Again, sorry if this idea is flawed but that would be my first attempt at trying to do this.
Filtering is the way to go. Have another look at it, I think you have overestimated it's difficulty; it's much easier than any of your other proposed solutions. Just set the filter's categoryBits to 0. You then need to call b2World::Refilter to update the value.

Superficially, sensors do seem to be an even easier solution, but there are problems:
a) You cannot easily turn on and off being a sensor, which is a deal breaker.
b) Filtering disables collision detection and collision response, while sensoring only disables the response. Unless you want the detection, you might as well save on performance and not use it. (though technically filtered objects still have some collision detection overhead compared with deleting it entirely, just not much).
BorisTheBrave wrote:
Just set the filter's categoryBits to 0. You then need to call b2World::Refilter to update the value.


Hmmm... okay, I guess that does sound pretty easy. I think I was just too lazy to try and figure out exactly how categoryBits work. 🙂

Thanks!

Original thread: https://box2d.org/forum/viewtopic.php?t=1337