I am trying to make it so that when I drag an object towards another drag object, they don’t overlap. But I also don’t want drag object two to move when I drag the first object towards it.
local function onDragTouch( event ) local d = event.target local phase = event.phase if "began" == phase then display.getCurrentStage():setFocus(d) d.isFocus = true d.x0 = event.x - d.x d.y0 = event.y - d.y elseif d.isFocus then if "moved" == phase then d.x = event.x - d.x0 d.y = event.y - d.y0 elseif "ended" == phase or "cancelled" == phase then display.getCurrentStage():setFocus( nil ) d.isFocus = false end end return true end objectOne=display.newRect(100, 100, 100, 100) physics.addBody(objectOne, "static") objectOne:addEventListener("touch", onDragTouch) objectTwo=display.newRect(100, 500, 50, 50) physics.addBody(objectTwo, "static") objectTwo:addEventListener("touch", onDragTouch)
How do I make it happen (with no gravity)? Thanks in advance.