please help us solve this problem

my friend and i are developing a game with many collisions. right now, we have three objects loaded that respond to collisions differently. there is the zombie, the star, and the happy face. we want it so that when the zombie collides wtih the happy face, the happy face disappears. we got that part working. now what we want is when the happy face touches the star the star diappears. but we are having the problem in which when the star collides with happy, both of them disappear. also when the zombie collides with the happy, happy and the star disappears. any help would be great.

function onCollision(event)

–print(“collide!”)

happy:removeSelf()

end

Runtime:addEventListener(“collision”, onCollision)

local function onCollision2( self, event )

if ( event.phase == “began” ) then

– Check if body still exists before removing

if( happy) then

happy:removeSelf()

happy = nil

end

end

end

– u kinda messed up the one u sent me so spawning in star now and creating its collision properties

local star = display.newImage( “starsmall.jpg” )

star.x = 400

star.y = 100

physics.addBody(star, “static”)

star.collType = “none”

physics.addBody( star, { bounce=10.0, friction=1.0 } )

function movestar()

transition.to(star,{time=900, x=math.random(300,500), y=math.random(0,200), onComplete=movestar})

end

movestar()

function onCollision(event)

–print(“collide!”)

star:removeSelf()

end

Runtime:addEventListener(“collision”, onCollision)

Instead of using a runtime collision event listener that monitors all collisions, you may be better off adding listeners to individual objects - so the zombie has its own collision listener, the star has its own listener and the happy face has its own listener.  This makes it easier to untangle which two objects have collided. 

Let’s say you attach a collision listener to the zombie - when it collides with another object, Corona will call the listener and tell you what the other object was and you can act accordingly.

Very roughly:

local function onZombieCollision( self, event ) if ( event.phase == "began" ) then --The object that the zombie collided with will be in event.other if (event.other == happyface) then --do something end end end --Set up the zombie collision listener zombie.collision = onZombieCollision zombie:addEventListener( "collision", zombie )

There’s more detail available in the collision detection guide.

Hope this helps.

Instead of using a runtime collision event listener that monitors all collisions, you may be better off adding listeners to individual objects - so the zombie has its own collision listener, the star has its own listener and the happy face has its own listener.  This makes it easier to untangle which two objects have collided. 

Let’s say you attach a collision listener to the zombie - when it collides with another object, Corona will call the listener and tell you what the other object was and you can act accordingly.

Very roughly:

local function onZombieCollision( self, event ) if ( event.phase == "began" ) then --The object that the zombie collided with will be in event.other if (event.other == happyface) then --do something end end end --Set up the zombie collision listener zombie.collision = onZombieCollision zombie:addEventListener( "collision", zombie )

There’s more detail available in the collision detection guide.

Hope this helps.