Hi
I am trying to set up a complex collision system where I have 6 floors at different heights, 6 catapults on each floor and waves of enemies moving on each floor. I want the catapult bullets to collide only with the respective floor line and the enemies that spawn in the correspondent line. So catapult bullet 3 collides with floor 3 and enemy 3 and ignores the other levels.
It is a collisionFilter nightmare as there are too many objects to handle with collisionFilters. I am trying to setup a simpler system to control what collides with what by using groupIndex, but it doesn’t seem to work.
In fact I have set up a simpler case to proof concept but groupIndex is not behaving as expected, unless I am missing something basic as I am a newbie.
Here is an example using categoryBits and maskBits which works fine. Circle collides with floor3
require ("physics")
physics.start()
physics.setDrawMode("hybrid")
physics.setGravity (0,20)
local collisionFilter1 = { categoryBits = 1, maskBits = 1 }
local collisionFilter2 = { categoryBits = 2, maskBits = 2 }
local collisionFilter3 = { categoryBits = 4, maskBits = 4 }
--- circle that falls and collides with floor 3, ignoring floor 1 & 2
circle = display.newCircle(100, 100, 10)
physics.addBody(circle, "dynamic", {filter = collisionFilter3})
-- create floors with three different collisionFilters
floor1 = display.newRect (0,500, 680, 2)
floor1:setFillColor (0,255,255)
physics.addBody(floor1, "static", {filter = collisionFilter1})
floor2 = display.newRect (0,700, 680, 2)
floor2:setFillColor (0,255,255)
physics.addBody(floor2, "static", {filter = collisionFilter2})
floor3 = display.newRect (0,900, 680, 2)
floor3:setFillColor (0,255,255)
physics.addBody(floor3, "static", {filter = collisionFilter3})
And here is the same case but using groupIndex as stated in the manual reference, but it doens’t work as expected. Circle collides with floor1
require ("physics")
physics.start()
physics.setDrawMode("hybrid")
physics.setGravity (0,20)
local collisionFilter1 = { groupIndex = 1 }
local collisionFilter2 = { groupIndex = 2 }
local collisionFilter3 = { groupIndex = 3 }
--- circle that falls and collides with floor 3, ignoring floor 1 & 2
circle = display.newCircle(100, 100, 10)
physics.addBody(circle, "dynamic", {filter = collisionFilter3})
-- create floors with three different collisionFilters
floor1 = display.newRect (0,500, 680, 2)
floor1:setFillColor (0,255,255)
physics.addBody(floor1, "static", {filter = collisionFilter1})
floor2 = display.newRect (0,700, 680, 2)
floor2:setFillColor (0,255,255)
physics.addBody(floor2, "static", {filter = collisionFilter2})
floor3 = display.newRect (0,900, 680, 2)
floor3:setFillColor (0,255,255)
physics.addBody(floor3, "static", {filter = collisionFilter3})
I have read all the infomration out there and I simply don’t understand why this simple case is not working with groupIndex. Am I missing something incredibly basic here? 
Thanks in advance [import]uid: 176273 topic_id: 31596 reply_id: 331596[/import]