by using this code i can move the ‘magnet’ on the Y axis but how can i link the ‘field’ to the ‘magnet’ so when i move the ‘magnet’ the ‘field’ moves with it?
magX = 300 magY = 100 field = display.newImageRect( "field.png", 330, 330 ) ; field.alpha = 0.2 field.name = "field" field.x = magX; field.y = magY physics.addBody( field, "static", { isSensor=true, radius=180, filter=fieldFilter } ) magnet = display.newImageRect( "magnet.png", 128, 128 ) magnet.name = "magnet" magnet.x = magX ; magnet.y = magY physics.addBody( magnet, "static", { bounce=0, radius=40, filter=magnetFilter } ) function magnet:touch( event ) Runtime:removeEventListener( "touch", screenTouch ) 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 = moverX --(event.x - event.xStart) + self.markX local y = (event.y - event.yStart) + self.markY self.x, self.y = x, y if self.y \> 500 then self.y = 500 end if self.y \< 100 then self.y = 100 end magX = self.x magY = self.y else Runtime:addEventListener( "touch", screenTouch ) end return true end magnet:addEventListener( "touch", magnet )