Contact filtering

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
zapwow
Prole
Posts: 48
Joined: Fri Oct 24, 2008 11:37 pm

Contact filtering

Post 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!
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Contact filtering

Post by bartbes »

I guess you need Shape:setMask()
User avatar
zapwow
Prole
Posts: 48
Joined: Fri Oct 24, 2008 11:37 pm

Re: Contact filtering

Post by zapwow »

Aha! I figured it would be under Body, or maybe World. Good to know.
User avatar
Tenoch
Citizen
Posts: 76
Joined: Mon Jul 21, 2008 7:49 am

Re: Contact filtering

Post 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.
"When in doubt, use brute force." Ken Thompson
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 206 guests