Changing collision filters after physics object is created

Not sure if this is a feature request, a bug or a brainfart.

I would like to change the collision filter categoryBits and maskBits on an object after it has been created, but there doesn’t seem to be a getter/setter for these attributes.

If I reassign the .filter on an object it does change the behavior somewhat, but not in any way I can actually identify as far as what it will react to, though it does appear to break some of my collision logic…

Am I missing something or is this a feature request ?

If this isn’t supported is there a suggested method of “cloning” a display/physics object that I might be able to change this during that process and kill off the donor ?

I’m not sure if there is enough of a physics object exposed to get all the relevant information to make a duplicate with the same position, velocity and other aspects that would need to be known to do that…

Any suggestions ?

I can work around it with a preCollision ( maybe ) but it would be a nice thing to have. [import]uid: 5210 topic_id: 3489 reply_id: 303489[/import]

You’re right, there aren’t any setters for changing the collision filter masks after you created the body. You would need to re-create the body and assign it the new filters in the addBody() constructor. Also, there isn’t a way to clone an existing physics object’s current properties to make this re-creation completely seamless. So I guess the answer is that this is a feature request. :wink:
Tim [import]uid: 8196 topic_id: 3489 reply_id: 10537[/import]

Hi Tim,

I’m facing the same problem at the moment. As a workaround, I tried calling physics.addBody() on the display object, passing in the new collision filter mask and this didn’t work. I tried calling object:removeSelf() first, before calling physics.addBody(), but of course this deletes the display object.

Is there another workaround for this problem? Is there a way to delete the physics body and not the display object?

Jared [import]uid: 23703 topic_id: 3489 reply_id: 26091[/import]

Depending on what you need to do, this may work (I’m using it successfully).

Change the physics object to isSensor=true:

myObject.isSensor = true

This will turn off all visible collisions until you set it back to false. Not quite as much flexibility as being able to change the collision filter, but it does work for what I need.
[import]uid: 31041 topic_id: 3489 reply_id: 29733[/import]

@scott0 i am trying to make Obj.isSensor = true this does not change all collisions happen how can i disable it ??? [import]uid: 74537 topic_id: 3489 reply_id: 67146[/import]