Hello,
I am trying to substract hero.hp value when zombie and hero are colliding, but
this method doesn’t work correctly.
- On first collision it substracts hero.hp value only one time
- on second collision it substracts hero.hp value while it’s colliding and after collision(I need it to substract hero.hp value only till collision ends)
My method:
local function zombieCollision(self, event)
if event.phase == "began" then
if event.other == hero then
hero.hp = hero.hp - 10
hp.text = "Hp:"..hero.hp
timer.performWithDelay(500, check)
function check()
if event.phase == "ended" then
print("ended")
else
hero.hp = hero.hp - 10
hp.text = "Hp:"..hero.hp
timer.performWithDelay(500, check)
end
end
end
end
end