admin管理员组文章数量:1395025
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 possibility of enabling the collision again after some time. Is there a way to do this? The hard thing about it, is that the object should not collide with any other object, but all the other objects should collide with each other.
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 possibility of enabling the collision again after some time. Is there a way to do this? The hard thing about it, is that the object should not collide with any other object, but all the other objects should collide with each other.
Share Improve this question edited Sep 21, 2015 at 18:35 d0n.key asked Sep 20, 2015 at 20:13 d0n.keyd0n.key 1,4834 gold badges20 silver badges43 bronze badges2 Answers
Reset to default 9You 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.
see
Matter.IBodyDefinition.isSensor
in order to disable physical collisions for the Body. The Body can still be used as a sensor for collisions.
本文标签: javascriptMatterjs Disable collision for one bodyStack Overflow
版权声明:本文标题:JavaScript, Matter.js: Disable collision for one body - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739473815a2164794.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论