JavaScript, Matter.js: Disable collision for one body

倾然丶 夕夏残阳落幕 提交于 2019-12-06 02:20:12

问题


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.


回答1:


You can use collision filters to do this. You can see an example of them working in the collision filtering demo and the source code.

They work similarly to how they do in Box2d, for which there is a good article you can use to get an idea of how they work.




回答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.



来源:https://stackoverflow.com/questions/32683832/javascript-matter-js-disable-collision-for-one-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!