Object Reference Point at Touch

Here is my problem: I want to move an object based off where you touch it. Right now, if you touch my object, it jerks to the reference point, then you can move it. I want my object to move around the touch point. Here is my current code:

local function lift(e)
if e.phase == “began” then
elseif e.phase == “moved” then
box3.x = e.x
box3.y = e.y
elseif e.phase == “ended” then
end
end
box3:addEventListener(“touch”, lift)

How can i fix this? [import]uid: 59735 topic_id: 37291 reply_id: 67291[/import]

local function lift(e) if e.phase == "began" then startX = e.x startY = e.y elseif e.phase == "moved" then box3.x = box3.x + (e.x - startX) box3.y = box3.y + (e.y - startY) startX = e.x startY = e.y elseif e.phase == "ended" then end end box3:addEventListener("touch", lift) [import]uid: 77199 topic_id: 37291 reply_id: 145522[/import]

If you look in the sample code and find the touch-drag example, there is code in there during the start phase that adds the difference between the touch and the target’s x,y and also adds that delta into the movement so that it doesn’t jerk on you.

Take a look at the code and apply it to yours.
[import]uid: 199310 topic_id: 37291 reply_id: 145524[/import]

local function lift(e) if e.phase == "began" then startX = e.x startY = e.y elseif e.phase == "moved" then box3.x = box3.x + (e.x - startX) box3.y = box3.y + (e.y - startY) startX = e.x startY = e.y elseif e.phase == "ended" then end end box3:addEventListener("touch", lift) [import]uid: 77199 topic_id: 37291 reply_id: 145522[/import]

If you look in the sample code and find the touch-drag example, there is code in there during the start phase that adds the difference between the touch and the target’s x,y and also adds that delta into the movement so that it doesn’t jerk on you.

Take a look at the code and apply it to yours.
[import]uid: 199310 topic_id: 37291 reply_id: 145524[/import]