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 )