Problem with collision Detection Help Needed!

So, I made a collision detection function for when the enemy is hit by the either bullet1 or bullet2 the enemy is removed. However, I want the bullets to be removed too! I tried adding another if then statement and an elseif (for the 2 bullets) but that doesn’t work. I will also need to add sounds and an explosion for the enemy if a bullet collides with it.

How do I modify the following code to add all this?
[lua]local function removeEnemy1( self, event )

if ( event.other == bullet ) then
self:removeSelf()

elseif ( event.other == bullet2 ) then
self:removeSelf()

end

end [import]uid: 54001 topic_id: 12219 reply_id: 312219[/import]

Try this

local function removeEnemy1( self, event )  
   
 if ( event.other == bullet ) then  
 self:removeSelf()  
 bullet:removeSelf()  
   
  
 elseif ( event.other == bullet2 ) then  
 self:removeSelf()  
 bullet2:removeSelf()   
 end  
   
end  
  

Now as for the sound, did you read the docs? if not here’s a link to the one explaining sound. http://developer.anscamobile.com/partner/audionotes

-Nick Homme [import]uid: 11769 topic_id: 12219 reply_id: 44497[/import]

if you want to do this clean and efficiently, then I would suggest the following.

You need a collision handler for the bullet and for the enemy. here is why. I don’t know how fast your game shoots, but each instance of bullet once spawned should be assign a collision event, which makes it easy to track and remove that object whether it hit the enemy or not. If it did not hit the enemy, it needs to be remove from memory once it goes off-screen. if you need a full working example let me know. [import]uid: 55144 topic_id: 12219 reply_id: 44549[/import]