avoiding collision in corona sdk

廉价感情. 提交于 2019-12-06 05:53:16

There is the second method to assign a groupIndex to each object. The value can be a positive or negative integer, and is a simpler way of specifying collision rules: objects with the same positive groupIndex value will always collide with each other, and objects with the same negative groupIndex value will never collide with each other.

local collisionFilter = { groupIndex = 2 }
physics.addBody(object1, {bounce = .2, density = 1, filter = collisionFilter})
physics.addBody(object2, {bounce = .2, density = 1, filter = collisionFilter})
russell305

You need to create a 'collision filter' adding both 'categoryBits' and 'maskBits' to every object. You assign a number to both them in physics body. Something like:

physics.addBody(object, {bounce = .2, density = 1, filter = {maskBits = 2, categoryBits = 4}})

Mask bits will only collide with an objects with same category bit. So an object with maskBit = 2 will only collide with an object with a categoryBit = 2.

You can assign any number you want as far a I know.

The concept is Collision Filtering. This link might help.

http://developer.anscamobile.com/forum/2010/10/25/collision-filters-helper-chart

The numbers need to be in powers of 2. Not any number.

I know this has already been answered but this might be useful for you. I used object.isSensor = true on my project so that even if the object has a physics body, it won't collide with other objects.

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