In my game, I’m shooting at monsters that are placed on various structures. When the monster is destroyed by a direct hit or the structures colliding with it, it calls the onMonsterPostPostCollsion function. However, if one monster collides into another monster, the simulator or device crashes.
local onMonsterPostCollision = function( self, event )
--I NEED TO MAKE IT NOT CRASH THE GAME IF 2 MONSTERS COLLIDE
if event.force \> 1 and self.isHit == false or self.isHit == false and self.x \>= 970 or self.isHit == false and self.x \< 0 then
audio.play( monsterPoofSound, { channel=5, onComplete=audio.stop( 5 ) } )
self.isHit = true
self.isVisible = false
self.isBodyActive = false
if poofTween then transition.cancel( poofTween ); end
greenPoof.x = self.x; greenPoof.y = self.y
greenPoof.alpha = 0
greenPoof.isVisible = true
local fadePoof = function()
transition.to( greenPoof, { time=500, alpha=0 } )
end
poofTween = transition.to( greenPoof, { time=50, alpha=1.0, onComplete=fadePoof } )
monsterCount = monsterCount - 1
if monsterCount \< 0 then monsterCount = 0; end
self:removeEventListener( "postCollision", self )
self.parent:remove( self )
print("self removed")
self = nil
local newScore = gameScore + mCeil(5000 \* event.force)
setScore( newScore )
print( "Score: "..newScore )
end
end
I’ve set up collision filters which seem to be fine but aren’t helping the problem. I’ve also tried to set it up as a global collision but that won’t allow the event.force comparison to work. I’ve also tried creating separate postCollision functions for the individual monsters but that didn’t work either.
I’m really lost on this on it’s the only thing besides debugging that’s preventing me from finishing the game so any help would be greatly appreciated.
Thanks in advance! [import]uid: 14032 topic_id: 9720 reply_id: 309720[/import]