In this fairly simple code sample, moving the dynamic circle around with the touch causes it to stick to the static rectangle. Can anyone explain why or perhaps offer a solution which otherwise leaves the physical behaviour unchanged, please?
main.lua:
[lua]require(“physics”)
physics.start()
physics.setGravity(0,0)
physics.setDrawMode(“hybrid”)
r = display.newRect( 100, 100, 100, 100 )
physics.addBody( r, “static”, {friction=0,density=1,bounce=0} )
a = display.newCircle( display.contentWidth/2, display.contentHeight/2, 25 )
physics.addBody( a, “dynamic”, {friction=0,density=1,bounce=0,radius=25,isSensor=true} )
a.isFixedRotation = true
function a:touch(e)
if (not a.hasFocus and e.phase == “began”) then
e.target.hasFocus = true
display.getCurrentStage():setFocus(e.target)
e.target.touchjoint = physics.newJoint(“touch”,e.target,e.x,e.y)
e.target.touchjoint.dampingRatio = 0
e.target.touchjoint.frequency = 10000000000
e.target.touchjoint.maxForce = 10000000000
e.target.isSensor = false
–timer.performWithDelay(1,function() e.target.bodyType = “kinetic” end, 1)
return true
elseif (a.hasFocus) then
if (e.phase == “moved”) then
e.target.touchjoint:setTarget(e.x,e.y)
else
display.getCurrentStage():setFocus(nil)
e.target.touchjoint:removeSelf()
e.target.hasFocus = false
e.target.isSensor = true
–timer.performWithDelay(1,function() e.target.bodyType = “static” end, 1)
timer.performWithDelay(1,function() e.target:setLinearVelocity( 0, 0 ) end, 1)
end
return true
end
return false
end
a:addEventListener(“touch”,a)[/lua] [import]uid: 8271 topic_id: 32702 reply_id: 332702[/import]