make object follow each other

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&nbsp; 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 ) &nbsp; &nbsp; if event.phase == "began" then &nbsp; &nbsp; &nbsp; &nbsp; self.markX = self.x &nbsp; &nbsp;-- store x location of object &nbsp; &nbsp; &nbsp; &nbsp; self.markY = self.y &nbsp; &nbsp;-- store y location of object &nbsp; &nbsp; elseif event.phase == "moved" then &nbsp; &nbsp; &nbsp; &nbsp; local x = moverX --(event.x - event.xStart) + self.markX &nbsp; &nbsp; &nbsp; &nbsp; local y = (event.y - event.yStart) + self.markY &nbsp; &nbsp; &nbsp; &nbsp; self.x, self.y = x, y &nbsp; &nbsp; if self.y \> 500 then self.y = 500 end if self.y \< 100 then self.y = 100 end&nbsp; magX = self.x magY = self.y else &nbsp; Runtime:addEventListener( "touch", screenTouch ) end &nbsp; &nbsp; return true end magnet:addEventListener( "touch", magnet )

fixed by adding transition.to( field, { time=1, x=self.x, y=self.y } )  to the   elseif event.phase == “moved” then

&nbsp; &nbsp; function magnet:touch( event ) &nbsp; &nbsp; Runtime:removeEventListener( "touch", screenTouch ) &nbsp; &nbsp; &nbsp; &nbsp; if event.phase == "began" then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.markX = self.x &nbsp; &nbsp;-- store x location of object &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.markY = self.y &nbsp; &nbsp;-- store y location of object &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif event.phase == "moved" then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local x = moverX --(event.x - event.xStart) + self.markX &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local y = (event.y - event.yStart) + self.markY &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.x, self.y = x, y &nbsp; &nbsp;-- move object based on calculations above &nbsp; &nbsp; --print("touch") &nbsp; &nbsp; &nbsp; &nbsp; if self.y \> 500 then self.y = 500 end &nbsp; &nbsp; if self.y \< 100 then self.y = 100 end&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; magX = self.x &nbsp; &nbsp; magY = self.y &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; transition.to( field, { time=1, x=self.x, y=self.y } ) &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; Runtime:addEventListener( "touch", screenTouch ) &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; return true &nbsp; &nbsp; end

fixed by adding transition.to( field, { time=1, x=self.x, y=self.y } )  to the   elseif event.phase == “moved” then

&nbsp; &nbsp; function magnet:touch( event ) &nbsp; &nbsp; Runtime:removeEventListener( "touch", screenTouch ) &nbsp; &nbsp; &nbsp; &nbsp; if event.phase == "began" then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.markX = self.x &nbsp; &nbsp;-- store x location of object &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.markY = self.y &nbsp; &nbsp;-- store y location of object &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif event.phase == "moved" then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local x = moverX --(event.x - event.xStart) + self.markX &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local y = (event.y - event.yStart) + self.markY &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.x, self.y = x, y &nbsp; &nbsp;-- move object based on calculations above &nbsp; &nbsp; --print("touch") &nbsp; &nbsp; &nbsp; &nbsp; if self.y \> 500 then self.y = 500 end &nbsp; &nbsp; if self.y \< 100 then self.y = 100 end&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; magX = self.x &nbsp; &nbsp; magY = self.y &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; transition.to( field, { time=1, x=self.x, y=self.y } ) &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; Runtime:addEventListener( "touch", screenTouch ) &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; return true &nbsp; &nbsp; end