Avoid Collision with specific objects

So guys, i’m creating a very simple tower defense game, were a bunch of monster walking in the tower direction and the player can shoot at them.

I was getting a problem with the monster collision, cause when two monster get to the destination they start to stack up, so i was trying to stop the monster from colliding with which other and i come up with this: 

 function monstro:preCollision(event) if(monstro.type == "monstro") then event.contact.isEnabled = false end end

Now i have two problems, when the monsters collide with which other during the walk, the bullets cannot collide with them, plus when the transition.to is over, the monster fall off the screen, because they don’t collide with the floor anymore.

What should i do?

Hello,

I am also developing a tower defense game and I encourage you to use collision filters.  You can then have the monsters’ collisions set to only trigger when colliding with bullets, and the bullets must be set only to collide with monsters.

Look up collision filters and you’ll see the great power this will have!

monsterCollisionFilter = { categoryBits = 1, maskBits = 6} -- This makes the monster be category 1 and makes it collide with category 2 and 4 (2+4=6) objects physics.addBody( monster, "kinematic", {filter=monsterCollisionFilter } ) bulletCollisionFilter = { categoryBits = 2, maskBits = 1} -- This makes the bullet category 2 and makes it collide with category 1 objects physics.addBody( bullet, {radius=5, filter=bulletCollisionFilter } ) bullet.isBullet = true goalCollisionFilter = { categoryBits = 4, maskBits = 1} -- This makes the monster be category 4 and makes it collide with category 1 objects physics.addBody( goal, "kinematic", {filter=goalCollisionFilter } ) 

The code above is off the top of my head, but you can look at this link above for a great tutorial on collision filters:

http://forums.coronalabs.com/topic/2128-collision-filters-helper-chart/

Thanks a lot man, this was exactly what a needed. 

Hello,

I am also developing a tower defense game and I encourage you to use collision filters.  You can then have the monsters’ collisions set to only trigger when colliding with bullets, and the bullets must be set only to collide with monsters.

Look up collision filters and you’ll see the great power this will have!

monsterCollisionFilter = { categoryBits = 1, maskBits = 6} -- This makes the monster be category 1 and makes it collide with category 2 and 4 (2+4=6) objects physics.addBody( monster, "kinematic", {filter=monsterCollisionFilter } ) bulletCollisionFilter = { categoryBits = 2, maskBits = 1} -- This makes the bullet category 2 and makes it collide with category 1 objects physics.addBody( bullet, {radius=5, filter=bulletCollisionFilter } ) bullet.isBullet = true goalCollisionFilter = { categoryBits = 4, maskBits = 1} -- This makes the monster be category 4 and makes it collide with category 1 objects physics.addBody( goal, "kinematic", {filter=goalCollisionFilter } ) 

The code above is off the top of my head, but you can look at this link above for a great tutorial on collision filters:

http://forums.coronalabs.com/topic/2128-collision-filters-helper-chart/

Thanks a lot man, this was exactly what a needed.