I have a radial gravity function that attaches a touch join between an object and a physics sensor, so when the object enters the physics sensor it is drawn to the center. I want to know how to remove the touch joint between the object and the physics sensor.
local field = display.newCircle( 0, 0, 300) ; field.alpha = 0.3 field.name = "field" field.x = 1200 field.y = 700 physics.addBody( field, "static", { isSensor=true, radius=100 } ) function eggplant:collision( event ) local self = event.target local otherName = event.other.name local function onDelay() if (self.action == "makeJoint" ) then self.hasJoint = true self.touchJoint = physics.newJoint( "touch", self, self.x, self.y ) self.touchJoint.frequency = .5 self.touchJoint.dampingRatio = 0 self.touchJoint:setTarget( event.other.x, event.other.y ) self.action = nil end end if ( event.phase == "began" and otherName == "field" and self.hasJoint == nil ) then local tr = timer.performWithDelay( 10, onDelay ) eggplant.action = "makeJoint" end end eggplant:addEventListener( "collision", eggplant )
I want the touch joint to be removed from between the eggplant and the “field” once the eggplant has left the field and the be created again once it re-enters the field.
Cheers