Hi,
Thanks for your reply.
Here’s the code I’m using to detect if three or more objects are together and then remove them:
[lua]
local destroyObject = function()
local left = -2000
local right = 2000
local up = -2000
local down = 2000
for k,v in pairs( objectGrid ) do
local totalHits = 0
local leftHits = physics.rayCast( v.x, v.y, v.x + left, v.y, “sorted” ) or {}
local rightHits = physics.rayCast( v.x, v.y, v.x + right, v.y, “sorted” ) or {}
local upHits = physics.rayCast( v.x, v.y, v.x, v.y + up, “sorted” ) or {}
local downHits = physics.rayCast( v.x, v.y, v.x, v.y + down, “sorted” ) or {}
– Count the horizontal hits
for i = 1, #leftHits do
if(leftHits[i].object.myImageNumber ~= v.myImageNumber) then
break
end
totalHits = totalHits + 1
end
for i = 1, #rightHits do
if(rightHits[i].object.myImageNumber ~= v.myImageNumber) then
break
end
totalHits = totalHits + 1
end
– Count the vertical hits
for i = 1, #upHits do
if(upHits[i].object.myImageNumber ~= v.myImageNumber) then
break
end
totalHits = totalHits + 1
end
for i = 1, #downHits do
if(leftHits[i].object.myImageNumber ~= v.myImageNumber) then
break
end
totalHits = totalHits + 1
end
if( totalHits > 1 ) then
v.readyToDestroyObject = true
found1 = true
end
print(totalHits)
end
if (found1) then
finalDestroyObject()
end
end
finalDestroyObject = function()
for k, v in pairs (objectGrid) do
if (v.readyToDestroyObject) then
v:removeSelf()
objectGrid[k] = nil
end
end
end
[/lua]
This code works well if the objects are like this:
However, if they are like that…
… it does not work anymore as only the upper left blue square is disapearing. In fact, it’s the only object which hits two objects at a time and the ray cast of the two other blue squares only detects one square.
And I would like the three blue squares to disapear…
Thanks in advance