How to make objects jump at desired position when tapped or dragged?

I want objects to be jumped at desired position, like in Subway Surfer.As that boy is tapped to its right it jumps on right rails, like that.How to do that.Currently I am using this code but it is not working as I want. 

local function dragball2( event )

    local ball2 = event.target

    local phase = event.phase

    if ( “began” == phase ) then

        – Set touch focus on the ball2

        display.currentStage:setFocus( ball2 )

        – Store initial offset position

        ball2.touchOffsetX = event.x - ball2.x

         ball2.touchOffsetY = event.y - ball2.y

    elseif ( “moved” == phase ) then

        – Move the ball2 to the new touch position

        ball2.x = event.x - ball2.touchOffsetX

        ball2.y = event.y - ball2.touchOffsetY

    elseif ( “ended” == phase or “cancelled” == phase ) then

        – Release touch focus on the ball2

        display.currentStage:setFocus( nil )

    end

    return true  

end

ball2:addEventListener( “touch”, dragball2 )

You need probably swipe detection. I find code for that 

http://sree.cc/corona-sdk/to-detect-swipe-direction

http://stackoverflow.com/questions/26573605/swipe-direction-corona-sdk

Hope this help :slight_smile:

You need probably swipe detection. I find code for that 

http://sree.cc/corona-sdk/to-detect-swipe-direction

http://stackoverflow.com/questions/26573605/swipe-direction-corona-sdk

Hope this help :slight_smile:

Yes Thanx  :rolleyes:

Yes Thanx  :rolleyes: