How to remove a touch joint?

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

https://docs.coronalabs.com/daily/api/type/Joint/removeSelf.html

So the use for you would probably include this at some point:

eggplant.touchJoint:removeSelf()

I was using this but it doesn’t seem to work

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
–COLLISION HANDLER
function objectCollide( self, event )

local otherName = event.other.name

local function onDelay( event )

local action = “”
. . .
elseif ( action == “leftField” ) then
self.hasJoint = false ; self.touchJoint:removeSelf() ; self.touchJoint = nil
end
end

. . .
elseif ( event.phase == “ended” and otherName == “field” and self.hasJoint == true ) then
local tr = timer.performWithDelay( 10, onDelay ) ; tr.action = “leftField”
end
end

Whoops added the line numbers in on accident

https://docs.coronalabs.com/daily/api/type/Joint/removeSelf.html

So the use for you would probably include this at some point:

eggplant.touchJoint:removeSelf()

I was using this but it doesn’t seem to work

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
–COLLISION HANDLER
function objectCollide( self, event )

local otherName = event.other.name

local function onDelay( event )

local action = “”
. . .
elseif ( action == “leftField” ) then
self.hasJoint = false ; self.touchJoint:removeSelf() ; self.touchJoint = nil
end
end

. . .
elseif ( event.phase == “ended” and otherName == “field” and self.hasJoint == true ) then
local tr = timer.performWithDelay( 10, onDelay ) ; tr.action = “leftField”
end
end

Whoops added the line numbers in on accident