Page 1 of 1
Help with filter data
Posted: Tue Jun 20, 2017 7:14 am
by Dialglex
I have tried to implement filter data into my game but I am having troubles.
I have the map, 4 cars, and bullets from each car. I want everything to collide with the map. I want the cars to collide with everything, except their own bullets. I want the bullets to collide with everything except their own car and all other bullets.
What filter data should I set each of these fixtures to be to do what I want them to do?
Re: Help with filter data
Posted: Wed Jun 21, 2017 4:44 am
by TheMajesticMagikarp
I think it would be easier for someone to help if you would provide the code you have written. I am also confused about why you would need for the bullet to not collide with the same car.
Re: Help with filter data
Posted: Wed Jun 21, 2017 6:42 am
by erasio
Actually the code should make very little difference since the question is specifically about physics filter data (groups, categories & masks).
The code to set those is trivial. So is integrating it into your system (be it ecs, classic oop, functional or a mix).
My suggestion to you OP would be. To mostly rely on negative groups and mask projectiles from one another.
Short overview about how this works. Firstly I'd suggest not using the setFilterData function. It's not well documented and this all at once type of thing. I prefer using the individual functions.
setGroupIndex,
setCategory and
setMask.
The group index is basically an override of the other settings. Positive means they'll always collide. Negative means they'll never collide.
So by setting each car and it's projectile to a specific group id (let's say -1 to -4). So each car will never collide with anything that belongs to it.
On top of that to prevent projectiles from colliding you can set the category of all projectiles to a shared value. And mask the same category. Since all projectiles share the same category and all have been set to ignore that category. Projectiles will never collide.
Cheers