How to avoid collision between physics bodies in corona ? The application that I am developing makes use of many physics bodies.I want collision to happen between two desired bodies,but the collision is happening between all the bodies in the system.Can anyone help me with a solution?
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})
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.
来源:https://stackoverflow.com/questions/8200505/avoiding-collision-in-corona-sdk