Posted 01 January 2016 - 03:54 PM
I need to get left and right directions (in global) based on a direction. How do I do it?
local directions = {"north", "east", "south", "west"}
local direction = "east"
local function getRight() -- returns the direction to the right of the current direction (defined by the 'direction' variable)
for i = 1, #directions do
if directions[i] == direction then
return directions[i % 4 + 1]
end
end
end
local function getLeft() -- returns the direction to the left of the current direction (defined by the 'direction' variable)
for i = 1, #directions do
if directions[i] == direction then
return directions[i == 1 and 4 or i - 1]
end
end
end
local function rotateAnticlockwise( x, y ) -- also known as left 90 degrees
return -y, x
end
local function rotateClockwise( x, y ) -- also known as right 90 degrees
return y, -x
end