schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 330 forks source link

More collision groups? #327

Closed Fxlr8 closed 6 years ago

Fxlr8 commented 6 years ago

Hi, I am trying to make a game where units can collide only with units of their own team. The docs say:

In JavaScript, you can use 32 valid groups (Math.pow(2,0) up to Math.pow(2,31)). If you use the mask 0 it won't match with any other shape group, and mask -1 will match all groups.

What if I need more than 32 collision groups? Or is it possible to force collisions between two given objects? This could also solve my case. I would just manually enable collisions between the objects I want.

P.S thank you for a great lib

Fxlr8 commented 6 years ago

I found that world's postBroadphase event is exactly what I need

here are the docs:

Fired after the Broadphase has collected collision pairs in the world. Inside the event handler, you can modify the pairs array as you like, to prevent collisions between objects that you don't want.

Awesome!