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 [import]uid: 84159 topic_id: 14678 reply_id: 314678[/import]

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:

[lua]local delayTable = {}
function delayTable:timer(event)
– destroy your object
end
timer.performWithDelay(200, delayTable)[/lua] [import]uid: 23693 topic_id: 14678 reply_id: 54312[/import]

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 [import]uid: 84159 topic_id: 14678 reply_id: 54381[/import]

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:

[lua]other.isOverlapping = true[/lua]

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

[lua]function onHit(event)
if event.object1.isOlverlapping then
– other logic
end
end[/lua]

I had to do something similar. My plane game, the player has shields. I need to detect the force of the impact. If the enemy hits the shields AND the player, he’ll hurt the player after the shields are gone IF the enemy is still overlapping the player. Would that work? [import]uid: 23693 topic_id: 14678 reply_id: 54426[/import]

You could use game states.

 local gameStates = {} --array to store the information of the different game states.  
 gameStates.shielded = 1  
 gameStates.notShielded = 2  
 local gameState = gameStates.notShielded   

Then when he collides set:

 gameState = gameStates.shielded 

Then for your code that you want to execute when he’s shielded do:

if gameState == gameStates.shielded then  
  
--code in here  
  
end  

Then all you need to do is maybe set the gamestate back to notShielded once its shielded is removed. You could put that if Statment above in an an enter frame too.
[import]uid: 87611 topic_id: 14678 reply_id: 54427[/import]