为什么使用冲撞过滤器清除所有碰撞?

时间:2019-07-16 20:42:10

标签: javascript matterjs

我有4个身体:2个球和2个平台。

我希望球能够重叠(没有碰撞),但仍会与两个平台碰撞。我已经通读了官方Matter.js Documentation并与collisionFilter demo一起玩,但是仍然无法掌握实现自己所需的条件。

let defaultCollision = 0x0001;
let ballCollision = 0x0002;
let holderCollision = 0x0004;
let floorCollision = 0x0008;

ball1 = Bodies.circle(...
  collisionFiler: { mask: ballCollision }
  ...
});

ball2 = Bodies.circle(...
  collisionFiler: { mask: ballCollision }
  ...
});
// ^ these balls don't collide, which is good.

platform1 = Bodies.circle(...
  collisionFiler: { mask: holderCollision }
  ...
});

platform2 = Bodies.circle(...
  collisionFiler: { mask: floorCollision }
  ...
});
// I don't understand why the balls pass right through these platforms...

任何帮助将不胜感激。

0 个答案:

没有答案