Hello All
Im currently trying to code a distance joint where the object can be swiped around the centre ring without any elasticity. At the moment it seems to not stay within the Circle and is prone to being dragged outside of it where it then bounces back if I let go.
Is there a way to fix its boundary exactly on the circle and so it can also be swiped within the circle only? The other issue I’m facing is constant freezing when dragging , i.e. doesn’t move with my finger unless I tap again, then again I’ve only tested this on a PC. Heres my code, am I going about it the right way?
local physics = require(“physics”)
physics.start()
physics.setGravity( 0,0 )
local staticBox = display.newCircle(display.contentCenterX,display.contentCenterY,150,150)
staticBox:setFillColor(0.2,0.2,1)
staticBox.strokeWidth = 10
physics.addBody(staticBox ,“static”)
local shape = display.newRect(20,20,50,50)
shape:setFillColor(1,0.2,0.4)
physics.addBody(shape,“dynamic”)
joint = physics.newJoint(“distance”,staticBox ,shape,staticBox.x,staticBox.y,shape.x,shape.y)
joint.dampingRatio = 0
joint.length = 150
– touch listener function
function shape:touch( event )
if event.phase == “began” then
self.markX = self.x – store x location of object
self.markY = self.y – store y location of object
elseif event.phase == “moved” then
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
self.x, self.y = x, y – move object based on calculations above
end
return true
end
shape:addEventListener( “touch”, myObject )