How to throw and NOT drag

Ok so this code makes the object Drag-able AND throw-able… i want it to just be throw-able… like when the player grabs the object they cant drag but if they swipe the object fly’s 

function dragBody( event, params ) local body = event.target local phase = event.phase local stage = display.getCurrentStage() if "began" == phase then stage:setFocus( body, event.id ) body.isFocus = true if params and params.center then body.tempJoint = physics.newJoint( "touch", body, body.x, body.y ) else body.tempJoint = physics.newJoint( "touch", body, event.x, event.y ) end if params then local maxForce, frequency, dampingRatio if params.maxForce then body.tempJoint.maxForce = params.maxForce end if params.frequency then body.tempJoint.frequency = params.frequency end if params.dampingRatio then body.tempJoint.dampingRatio = params.dampingRatio end end elseif body.isFocus then if "moved" == phase then body.tempJoint:setTarget( event.x, event.y ) elseif "ended" == phase or "cancelled" == phase then stage:setFocus( body, nil ) body.isFocus = false body.tempJoint:removeSelf() end end return true end player:addEventListener( "touch", dragBody)

See this thread:

https://forums.coronalabs.com/topic/57339-swipe-to-throw-object-without-dragging/

tried it… doesnt work… like it moves a little but but it feels so laggy and it doesnt fling it… and it drags…

The theory is all there. You just need to experiment with the code to get it to do what you want. 

fe:

centerX = display.contentCenterX centerY = display.contentCenterY screenTop = math.floor(display.screenOriginY) screenLeft = math.floor(display.screenOriginX) screenBottom = display.contentHeight - screenTop screenRight = display.contentWidth - screenLeft screenWidth = screenRight - screenLeft screenHeight = screenBottom - screenTop local physics = require("physics") physics.start() local leftWall = display.newRect(screenLeft - 10, centerY, 20, screenHeight) local rightWall = display.newRect(screenRight + 10, centerY, 20, screenHeight) local topWall = display.newRect(centerX, screenTop - 10, screenWidth, 20) local bottomWall = display.newRect(centerX, screenBottom + 10, screenWidth, 20) physics.addBody(leftWall, "static") physics.addBody(rightWall, "static") physics.addBody(topWall, "static") physics.addBody(bottomWall, "static") local square = display.newRect(centerX, centerY, screenWidth\*.075, screenWidth\*.075) physics.addBody(square) square.gravityScale = 0 local function touchListener(event) local phase=event.phase if phase == "began" then square:setLinearVelocity(0,0) elseif phase == "moved" then print("event.x = "..event.x) print("event.y = "..event.y) elseif phase == "cancelled" or phase == "ended" then local eventXMove = (event.xStart - event.x)\*-1 local eventYMove = (event.yStart - event.y)\*-1 print("0--------------------------") print("eventXMove = "..eventXMove) print("eventYMove = "..eventYMove) local vx, vy = square:getLinearVelocity() square:setLinearVelocity(eventXMove, eventYMove) end end Runtime:addEventListener("touch", touchListener)

See this thread:

https://forums.coronalabs.com/topic/57339-swipe-to-throw-object-without-dragging/

tried it… doesnt work… like it moves a little but but it feels so laggy and it doesnt fling it… and it drags…

The theory is all there. You just need to experiment with the code to get it to do what you want. 

fe:

centerX = display.contentCenterX centerY = display.contentCenterY screenTop = math.floor(display.screenOriginY) screenLeft = math.floor(display.screenOriginX) screenBottom = display.contentHeight - screenTop screenRight = display.contentWidth - screenLeft screenWidth = screenRight - screenLeft screenHeight = screenBottom - screenTop local physics = require("physics") physics.start() local leftWall = display.newRect(screenLeft - 10, centerY, 20, screenHeight) local rightWall = display.newRect(screenRight + 10, centerY, 20, screenHeight) local topWall = display.newRect(centerX, screenTop - 10, screenWidth, 20) local bottomWall = display.newRect(centerX, screenBottom + 10, screenWidth, 20) physics.addBody(leftWall, "static") physics.addBody(rightWall, "static") physics.addBody(topWall, "static") physics.addBody(bottomWall, "static") local square = display.newRect(centerX, centerY, screenWidth\*.075, screenWidth\*.075) physics.addBody(square) square.gravityScale = 0 local function touchListener(event) local phase=event.phase if phase == "began" then square:setLinearVelocity(0,0) elseif phase == "moved" then print("event.x = "..event.x) print("event.y = "..event.y) elseif phase == "cancelled" or phase == "ended" then local eventXMove = (event.xStart - event.x)\*-1 local eventYMove = (event.yStart - event.y)\*-1 print("0--------------------------") print("eventXMove = "..eventXMove) print("eventYMove = "..eventYMove) local vx, vy = square:getLinearVelocity() square:setLinearVelocity(eventXMove, eventYMove) end end Runtime:addEventListener("touch", touchListener)