@Brent: just out of curiosity, what did you suspect it was? Here is my code:
Creation of the magnet objects (A and B in my original post):
-- Create visible magnet local magnet = display.newImageRect("images/magnet.png", 60, 60) magnet.x = 100 magnet.y = 100 magnet.objectId = properties.objectId.magnet physics.addBody(magnet, "dynamic", { friction = 0.0, bounce = 0.0, isSensor = true, radius = (magnet.width \* 0.5) }) magnet.gravityScale = 0.0 magnet.collision = onMagnetCollision magnet:addEventListener("collision", magnet) sceneGroup:insert(magnet) -- Create an area in which the magnetic pull is active local magnetArea = display.newCircle(levelDetails.magnets[i].x, levelDetails.magnets[i].y, 120) magnetArea.isVisible = false magnetArea.isHitTestable = true magnetArea.objectId = properties.objectId.magnetArea magnetArea.stickyObject = magnet magnet.stickyObject = magnetArea physics.addBody(magnetArea, "dynamic", { friction = 0.0, bounce = 0.0, isSensor = true, radius = (magnetArea.width \* 0.5) }) magnetArea.gravityScale = 0.0 sceneGroup:insert(magnetArea) -- Create a weld joint between the magnet and the magnet area so that they move together local weldJoint = physics.newJoint("weld", magnet, magnetArea, 0, 0)
In the “began” phase of the collision detection of the other object (C in my original post):
if ((otherObject.isInMagnet == nil) or (otherObject.isInMagnet == false)) then timer.performWithDelay(10, function() otherObject.stickyObject.isInMagnet = true otherObject.stickyObject.touchJointMagnet = physics.newJoint("touch", otherObject.stickyObject, otherObject.x, otherObject.y) otherObject.stickyObject.touchJointMagnet.frequency = 0.30 otherObject.stickyObject.touchJointMagnet.dampingRatio = 1 otherObject.stickyObject.touchJointMagnet:setTarget(spaceship.x, spaceship.y) end) end
In the “ended” phase of the collision detection of the other object (C in my original post):
timer.performWithDelay(10, function() if (otherObject.stickyObject.isInMagnet) then otherObject.stickyObject.isInMagnet = false; otherObject.stickyObject.touchJointMagnet:removeSelf(); otherObject.stickyObject.touchJointMagnet = nil end end, 1)
The “stickyObject”-thing is just to be able to reference A from B and vice versa.
The above code gives the result that A and B still continue to move after the touch joint is removed.