So i have this code… you can put it into any main.lua and it will work…
local physics = require("physics") physics.start() local box = display.newRect( display.contentCenterX, display.contentCenterY - 200, 30, 30 ) box:setFillColor( 1, 0, 0 ) box.rotation = 45 box.myName = "box" physics.addBody( box, "dynamic", { bounce = 0 } ) local leftLine = display.newRect( display.contentCenterX - 45, display.contentCenterY + 200, 20, 100 ) leftLine:setFillColor( 0, 0, 1 ) leftLine.rotation = -45 leftLine.myName = "leftLine" physics.addBody( leftLine, "static", { bounce = 0 } ) local rightLine = display.newRect( display.contentCenterX + 45, display.contentCenterY + 200, 20, 100 ) rightLine:setFillColor( 0, 0, 1 ) rightLine.rotation = 45 rightLine.myName = "rightLine" physics.addBody( rightLine, "static", { bounce = 0 } ) local function onCollision( event ) if event.phase == "began" then if event.target.myName == "box" and event.other.myName == "leftLine" and event.other.myName == "rightLine" then print("hiii") end end end box:addEventListener( "collision", onCollision )
So what i want is the onCollision function to fire when the box touches both of the line… and nothing to happen if the box touches just one…
Thanks!