I’m writing a game where I’d like to check for overlap between two non-moving objects. I was hoping to be able to somehow use physics and collision to do this, but I’m having problems. Seems the physics based collision testing is only checking collisions between the edge of objects and not internally?
The example below shows this:
\_W = display.contentWidth \_H = display.contentHeight local poly = nil local physics = require "physics" physics.start() physics.setGravity(0,3) local function onCollision( event ) if (event.phase == "began" ) then poly:setFillColor(1,1,0) end end Runtime:addEventListener("collision", onCollision) local vertices = {-200,-200, 200,-200, 200, 200, -200,200} poly = display.newPolygon(\_W/2, \_H/2, vertices ) poly:setFillColor(0,0,1) physics.addBody( poly, "static", { isSensor = true } ) local circle = display.newCircle(\_W/2, \_H/2, 50) circle:setFillColor(1,0,0) physics.addBody( circle, "dynamic", { isSensor = true } )
There is no collision detection before the moving object crosses the border of the other object.
So, is there a way to detect if a non-moving object is (partially) inside another non-moving object with the physics library?