Issue getting a collision to work.

Hello,

I have my code set up so that three different types of objects drop randomly. When the objects hit the ground, I would like the instance of the object that hit the ground to disappear. Unfortunately, I have not been able to get this to work. My physics objects are currently defined within a function and my ground object is defined outside of the function. Any help on this would be appreciated.

Thank you. [import]uid: 47722 topic_id: 11975 reply_id: 311975[/import]

Where they are defined shouldn’t be a problem.
just make sure the physics bodies are working correctly by setting

 physics.setDrawMode('hybrid') 

if they are showing up properly, make sure the collision is being reported using

local function onCollision( event )  
 if ( event.phase == "began" ) then  
   
 print( "began: " .. event.object1.myName .. " & " .. event.object2.myName )  
   
 elseif ( event.phase == "ended" ) then  
   
 print( "ended: " .. event.object1.myName .. " & " .. event.object2.myName )  
   
 end  
end  
   
Runtime:addEventListener( "collision", onCollision )  

That code was taken from here http://developer.anscamobile.com/content/game-edition-collision-detection

If they are collding, then you need to use a simple

 event.object1:removeSelf() 

put that last line below the
[lua]elseif ( event.phase == “ended” ) [/lua]
then line [import]uid: 34945 topic_id: 11975 reply_id: 43676[/import]

Thanks so much innominata! Using what you said, I was able to write the functions that worked perfectly for my app! I think I was confused by the whole event.object1.myName part, but I figured it out now. Thank you very much for the help [import]uid: 47722 topic_id: 11975 reply_id: 43696[/import]

oh, the object1.myName is a variable you set so you can tell your objects apart…

x.myName = ‘that thing with a name’

when it collides, you check the ‘myName’ property for a reminder
[import]uid: 34945 topic_id: 11975 reply_id: 43965[/import]

Yep. Thanks. That is really helpful. Now I just have to figure out how to restart a level. [import]uid: 47722 topic_id: 11975 reply_id: 43967[/import]

using director, create a blank scene, and go
timer.performWithDelay(100,function() director.changeScene(‘currentScene’) end,1)
director.changeScene(‘blank’)

i think that works, either that or restart the level manually (easy if you program properly, devilish if you dont) [import]uid: 34945 topic_id: 11975 reply_id: 43979[/import]