non-physics object collision / touching event

I have two objects: a circle and a moving rectangle.

I want to trigger an event when the two objects touch.

I just want an event triggered. I do not want them to bounce off each other.

Make them dynamic physics objects and set their isSensor property to true. Check the docs to see how. You will need to add a listener to each (or a global Runtime listener, but I don’t recommend this) to receive the event.

thanks Horacebury,

that was a good step. Unfortunately my code doesn’t trigger the event i want.

Here is my code:

rectCollisionFilter = { categoryBits = 8, maskBits = 16 } rectBodyElement = { friction=0.4, bounce=0.8, filter=rectCollisionFilter } local fireRect = display.newRect( 125, 30, 70, 230 ) physics.addBody( fireRect, "static", rectBodyElement ) fireRect.myName = "fireRect" circleCollisionFilter = { categoryBits = 16, maskBits = 8} circleBodyElement = { friction=0.4, bounce=0.8, filter=circleCollisionFilter } local testCircle = display.newCircle( 200, 230, 70 ) testCircle.myName = "CIRCLE1" testCircle.isSensor = true physics.addBody( testCircle, "static", circleBodyElement ) local function onLocalCollision( self, event )     print( "COLLIDE" )     print( "target " .. event.target.myName )     print( "other " .. event.other.myName ) end testCircle.collision = onLocalCollision testCircle:addEventListener( "collision", testCircle )

I move the fireRect object over the circle but my function is never called.

What am I doing wrong?

at least one body must be dynamic (as per @horacebury already) statics do not collide w each other

Make them dynamic physics objects and set their isSensor property to true. Check the docs to see how. You will need to add a listener to each (or a global Runtime listener, but I don’t recommend this) to receive the event.

thanks Horacebury,

that was a good step. Unfortunately my code doesn’t trigger the event i want.

Here is my code:

rectCollisionFilter = { categoryBits = 8, maskBits = 16 } rectBodyElement = { friction=0.4, bounce=0.8, filter=rectCollisionFilter } local fireRect = display.newRect( 125, 30, 70, 230 ) physics.addBody( fireRect, "static", rectBodyElement ) fireRect.myName = "fireRect" circleCollisionFilter = { categoryBits = 16, maskBits = 8} circleBodyElement = { friction=0.4, bounce=0.8, filter=circleCollisionFilter } local testCircle = display.newCircle( 200, 230, 70 ) testCircle.myName = "CIRCLE1" testCircle.isSensor = true physics.addBody( testCircle, "static", circleBodyElement ) local function onLocalCollision( self, event )     print( "COLLIDE" )     print( "target " .. event.target.myName )     print( "other " .. event.other.myName ) end testCircle.collision = onLocalCollision testCircle:addEventListener( "collision", testCircle )

I move the fireRect object over the circle but my function is never called.

What am I doing wrong?

at least one body must be dynamic (as per @horacebury already) statics do not collide w each other