Hi everyone.
Here’s my problem:
I have the following function to add physical bodys:
function addSensor(x, y, width, height) x = x + width / 2 y = y +height / 2 Sensor[currentSensor] = display.newRect(x,y,width,height) Sensor[currentSensor].x = x Sensor[currentSensor].y = y Sensor[currentSensor].width = width Sensor[currentSensor].height = height Sensor[currentSensor]:setFillColor(80,80,80) Sensor[currentSensor].ID = "obstacle" physics.addBody(Sensor[currentSensor], "static", { bounce = 0, friction = 1.0, filter = {maskBits =5, categoryBits = 2} } ) currentSensor = currentSensor + 1 end
It’s called like this:
addSensor (200,0,50,50) addSensor (300,100,50,50) addSensor (400,200,50,50)
My previous collision detection looked like this:
local function onCollision(event) if (event.phase == "began") then if (event.object1.ID == "obstacle") or (event.object2.ID == "obstacle") then if (event.object1.ID == "balloon") or (event.object2.ID == "balloon") then balloon.paused = true balloon.canJump = true collX, collY, collW, collH = obstacle.x, obstacle.y, obstacle.width, obstacle.height limit = (collW + collH) / 4 if limit \> 120 then limit = 120 end end end end end
The problem is, all the physical objects have the same “ID” (obstacle).
How do i find out on which of them the collision occured?
Best regards.