Javascript, Matter.js: Disable Collision For One Body
As already mentioned in the title, I am looking for a way, to disable every collision of a body in Matter.js. It should still be linkable with Constraints, and there should be the
Solution 1:
You can use collision filters, like so:
const body = Matter.Bodies.rectangle(100, 100, 50, 50);
// turns off collisions
body.collisionFilter = {
'group': -1,
'category': 2,
'mask': 0,
};
From the docs:
If the two bodies have the same non-zero value of
collisionFilter.group
, they will always collide if the value is positive, and they will never collide if the value is negative.Using the category/mask rules, two bodies
A
andB
collide if each includes the other's category in its mask, i.e. (categoryA & maskB) !== 0
and(categoryB & maskA) !== 0
are both true.
Solution 2:
see
Matter.IBodyDefinition.isSensor
in order to disable physical collisions for the Body. The Body can still be used as a sensor for collisions.
Post a Comment for "Javascript, Matter.js: Disable Collision For One Body"