matter-js
matter-js copied to clipboard
Parts of a body not respecting collision filter
So, I'm trying to disable collision on certain parts of a body depending upon an event. It seems that applying collisionFilter on a body part doesn't really do anything. Is this a bug or the way it is implemented.
I'm not talking about collision with parts of the same body, but with the world
const mainBody = Bodies.rectangle(0, 0, w * 0.4, h * 0.8, {
chamfer: { radius: w * 0.2 },
label: 'main',
});
const sensors = {
bottom: Bodies.rectangle(0, h * 0.4, w * 0.25, 10, { isSensor: true, label: 'bottom' }),
front: Bodies.rectangle(w * 0.225, 0, 20, h * 0.5, { isSensor: true, label: 'front', }),
back: Bodies.rectangle(-w * 0.225, 0, 10, h * 0.5, { isSensor: true, label: 'back' }),
};
sensors.front.collisionFilter = {
group: -1,
category: -1,
mask: 1 << 2
}
const compoundBody = Body.create({
parts: [mainBody, sensors.bottom, sensors.front, sensors.back],
frictionStatic: 0,
frictionAir: 0.02,
friction: 0.1,
// The offset here allows us to control where the sprite is placed relative to the
// matter body's x and y - here we want the sprite centered over the matter body.
render: { sprite: { xOffset: 0.35, yOffset: 0.45 } },
});
this.body = compoundBody;
That's right currently for performance and simplicity reasons only the parent body collisionFilter is used rather than from each part, so I think you might need to use constraints to do something like this.