Something like:
local isColliding = false function onCollision(event) local function removeOnPlayerHit(obj1, obj2) if((obj ~= nil ) and ((obj.id == "enemy") or (obj.id == "enemy2") or (obj.id == "enemy3") or (obj.id == "enemy4"))) then display.remove(obj) end end local function showPlayerHit() local tmr\_onPlayerHit = timer.performWithDelay(1, playerHit, 1) end if event.phase == "began" then if isColliding then return end if((event.object1.id == "enemy" or event.object1.id == "enemy2" or event.object1.id == "enemy3" or event.object1.id == "enemy4") and event.object2.id == "character") then showPlayerHit() removeOnPlayerHit(event.object1, nil) elseif(event.object1.id == "character" and (event.object2.id == "enemy" or event.object2.id == "enemy2" or event.object2.id == "enemy3" or event.object2.id == "enemy4")) then showPlayerHit() removeOnPlayerHit(nil, event.object2) end elseif event.phase == "ended" then isColliding = false end end
or something like that. (untested). You might want to the body part ID that trigger the first collision instead of a boolean and ignore any “began” phases from the different body parts. That information would be in event.element1 for object1 and event.element2 for object2.
Now to expand your game, this last idea could offer you a cool feature. You could go back into Physics Engine and re-generate your scorpion in a way that one physics body is its pinchers, one physics body is its body and another is it’s tail/stinger. If your hero collides with the pinchers/tail he looses a life. If he collides with the body, he kills the scorpion.
