Matter-js: Disable collision between relatives bodies

Created on 24 Apr 2020  路  4Comments  路  Source: liabru/matter-js

How to disable collision between relatives bodies? For example, I have a lot of balls, they fall and collide by walls, but they should not collide with themselves. Please someone explain how to make it?

question

All 4 comments

It looks like you're looking for "Collision Filtering"...

https://brm.io/matter-js/demo/#collisionFiltering
https://github.com/liabru/matter-js/blob/master/examples/collisionFiltering.js

I haven't tried it. But if I'm understanding this correctly, it looks like you'd create a "walls" category, then set a "collisionFilter" on the balls, where the mask would be the "walls".

It looks like you're looking for "Collision Filtering"...

https://brm.io/matter-js/demo/#collisionFiltering
https://github.com/liabru/matter-js/blob/master/examples/collisionFiltering.js

I haven't tried it. But if I'm understanding this correctly, it looks like you'd create a "walls" category, then set a "collisionFilter" on the balls, where the mask would be the "walls".

No, it not works for me. Because relatives bodies collide between themselves, cause they gonna have the same mask.

Well, how many balls are there? If it's 30 or less, why not create a group for each ball, one for walls and one general group?

I think you could set the balls all to have a negative group e.g. -1 and the walls a positive group (default is 0 so that's fine).

Would that work? You can combine these with masks too. If you need something really custom, you could patch Detector.canCollide with your own logic.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moe091 picture moe091  路  3Comments

maximilianberndt picture maximilianberndt  路  4Comments

djipco picture djipco  路  4Comments

christianmalek picture christianmalek  路  4Comments

jack-guy picture jack-guy  路  3Comments