Overlapping objects

Hi,

I'm implementing shield for my actor. If the actor collide with shield, the actor will be shielding for 5 second. If the actor is being shielded, the enemy can't destroy the actor. The problem is when the enemy move over the shielded actor and while the enemy is still overlapping the actor the shield time is over, I can't get the actor destroyed.

I use "began" phase of collision to destroy the actor when it collide with enemy and I know it is because the collision already fire while the actor is being shielded so it won't fire again even they are overlapping thus the unshielded actor can't be destroyed.

Look like the solution is to call a function (from the function I change shield var to false) to check if the object is still overlapping and then destroy the actor.

Any suggestion? Thanks.

Steve

Is it a physics object? If so, you can't remove physics objects during collisions. In older builds, it'd crash. In newer builds, removeBody will return false. Use a timer to wait, like so:

1
2
3
4
5
local delayTable = {}
function delayTable:timer(event)
        -- destroy your object
end
timer.performWithDelay(200, delayTable)

I think you don't understand my problem. Probably I didn't explain it clearly. I'm using physics object. I'm trying to find a way to detect if the object is overlapping now.

Steve

Without seeing code it's hard to tell, but I think I get it. Your idea of having a flag on the other actor to say:

other.isOverlapping = true

Makes sense because then in your collision, you can go:

1
2
3
4
5
function onHit(event)
   if event.object1.isOlverlapping then
      -- other logic
   end
end

You could use game states.

1
2
3
4
        local gameStates    = {} --array to store the information of the different game states.
        gameStates.shielded  = 1
        gameStates.notShielded   = 2
        local gameState     = gameStates.notShielded 
views:1590 update:2011/9/26 8:07:09
corona forums © 2003-2011