Advertisement
alestane

Swipe movement (convert)

Jan 2nd, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     local function touchFunkx(event)
  2.         local xDistance, yDistance = event.x - event.xStart, event.y - event.yStart
  3.  
  4.         if event.phase == "ended" then
  5.             local distance = math.sqrt(xDistance * xDistance + yDistance * yDistance)
  6.             local angle = (math.atan2(yDistance, xDistance) * 180 / math.pi + 45) % 360
  7.             local dX, dY = 0, 0
  8.             if angle < 90 then
  9.                 dX = 1
  10.             elseif angle < 180 then
  11.                 dY = 1
  12.             elseif angle < 270 then
  13.                 dX = -1
  14.             else
  15.                 dY = -1
  16.             end
  17.         end
  18.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement