Page 1 of 1

Contact filtering

Posted: Sun Jul 05, 2009 6:15 pm
by zapwow
Hello,
I was hoping to use the box2d's contact filtering to determine whether or not certain objects should be able to collide with each other. For example, I want a player to pass right through his own bullets. I can't find it in the LÖVE physics documentation. Is it not yet implemented?
Thanks!

Re: Contact filtering

Posted: Sun Jul 05, 2009 6:20 pm
by bartbes
I guess you need Shape:setMask()

Re: Contact filtering

Posted: Sun Jul 05, 2009 6:22 pm
by zapwow
Aha! I figured it would be under Body, or maybe World. Good to know.

Re: Contact filtering

Posted: Sun Jul 05, 2009 8:27 pm
by Tenoch
Yep, for each shape (either circle or polygon) you can:

1. put it in one or more categories using :setCategory()
2. designate which categories the shape should not collide with, using :setMask()

These functions take any number of arguments which are numbers from 1 to 16 (there can be no more than 16 categories), for instance:

Code: Select all

myshape:setCategory(1,4,5)
myshape:setMask(2,3)
The similar functions setCategoryBits() and setMaskBits(), which ask for a number that corresponds to a bit set for each category, are going to be removed in the next release of LÖVE, because they are far more annoying to use.