I'm making a 2D game in Corona for Android/iPhone that is similar to Volfied. In my game, the user has to touch the screen to draw a line for the character to move along. How can I force the lines to be orthogonal, as opposed to being free-drawn?

I can detect the swipe's direction with atan2 and the difference of X and Y, but I am having trouble determining the pivot points of the line. How can I determine when the line should make a turn?

You can see what I am trying to accomplish in this video of Volfied gameplay.


1 Answer 1


Here's a sample that shows how to obtain the beginning and end coordinates: http://developer.coronalabs.com/code/mark

Essentially to lock it to orthogonal, you need to find which orthogonal direction is the smallest angle from the given angle, and set your beginX and beginY appropriately.

For example, knowing that you're swiping from left to right I might do the following:

local swipeDifferenceX = beginX - endX
local swipeDifferenceY = beginY - endY

// If the user moved further in the X direction
if(swipeDifferenceX >= swipeDifferenceY)
    endY = beginY
    endX = beginX

This will likely require some playing around with and I probably messed up some logic since I only have a few minutes to respond, but I trust you can figure out the rest.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .