user1030769
user1030769

Reputation:

avoiding collision in corona sdk

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?

Upvotes: 2

Views: 3126

Answers (5)

user1597438
user1597438

Reputation: 2221

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.

Upvotes: 1

DogCoffee
DogCoffee

Reputation: 19946

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

Upvotes: 1

k2fx
k2fx

Reputation: 1271

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})

Upvotes: 2

Babu
Babu

Reputation: 127

The concept is Collision Filtering. This link might help.

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

Upvotes: 1

russell305
russell305

Reputation: 31

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.

Upvotes: 3

Related Questions