Collision between two specific objects

Hi,

I have an object that grows with a touch event (with transition) …

I want to create a function where every time the touch is released, another specific object that overlaps with it is removed.

this is what i coded -

function ballIncrease()
tweenReference =  transition.to( ball, {time=2000, xScale=5, yScale=5} )
end

function ballReturn()
function onCollision(event)
    ob1 = event.object1
        ob2 = event.object2
    if ob1.type == “ball” and ob2.type == “crate” then
    score=score+1
    print(score)
    end
end
    transition.to( ball, {time=100,xScale=1, yScale=1} )
    transition.cancel(tweenReference)
ball.addEventListener(“collision”, onCollision)
end

onTouch = function( event )
    if(event.phase == “began”)then
        ballIncrease()
    elseif (event.phase == “ended” or event.phase == “cancelled”) then
        ballReturn()
end
end

Runtime:addEventListener( “touch”, onTouch )
 

the objects that overlap the “ball” object are added to an array earlier in the scene with this code -

i=0
local crateTable = {}

function dropAction()
crate= display.newImage(“crate.png”)
crate.type = “crate”
crate.width = 50
crate.height= 50
crate.y=-30
crate.x= math.random(50,900)
crate.rotation=50
physics.addBody(crate, “dynamic”, {bounce=0.5})
table.insert(crateTable,crate)
crate = crateTable[i]
print(i)
local function crateRemove()
            
                table.remove(crateTable, i)
                if crate~= nil then
                crate:removeSelf()
                crate = nil
            end
 end
local function onLocalCollision( self, event )
        if ( event.phase == “began” ) then
timer.performWithDelay(1000, crateRemove)
end        
end
    crate.collision = onLocalCollision
    crate:addEventListener( “collision”, crate)]]
end

local function dropBox()
timer.performWithDelay(math.random(500, 1500), dropAction);
end

local function gameLoop(event)
if event.time - timeLastEnemy >= math.random(1000, 5000) then
dropBox()
timeLastEnemy = event.time
i=i+1
end
end

I doesn’t really work…I’d love some help please :slight_smile: