Changing collision filters after physics object is created

4 replies [Last post]
klingk
User offline. Last seen 3 weeks 4 days ago. Offline
Joined: 21 Feb 2010

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.

Replies

Tim
User offline. Last seen 3 years 15 weeks ago. Offline
Alumni
Joined: 12 Aug 2010

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. ;-)

Tim

jared
User offline. Last seen 2 years 32 weeks ago. Offline
Joined: 20 Jan 2011

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

scott0
User offline. Last seen 18 hours 20 min ago. Offline
Joined: 29 Jan 2011

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.

test driver
User offline. Last seen 12 weeks 7 hours ago. Offline
Joined: 7 Jul 2011

@scott0 i am trying to make Obj.isSensor = true this does not change all collisions happen how can i disable it ???

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.