Hi everyone, I started Corona about 2 weeks ago.
I’ve spent the past few hours learning about rotating objects. I attempted to make function that rotates an object (rect1) to point towards another object (rect2). I couldn’t find any code online for this function so I spent a long time figuring it out on my own, here it is:
[lua]local function rotateRect1()
xDif = rect2.x - rect1.x
yDif = rect2.y - rect1.y
if rect1.x > rect2.x and rect1.y > rect2.y then – Upper Right
rect1.rotation = ((math.atan(yDif/xDif)) * 180/math.pi) - 90
elseif rect1.x > rect2.x and rect1.y < rect2.y then – Lower Right
rect1.rotation = ((math.atan(yDif/xDif)) * 180/math.pi) - 90
elseif rect1.x < rect2.x and rect1.y > rect2.y then – Upper Left
rect1.rotation = ((math.atan(yDif/xDif)) * 180/math.pi) - 90
elseif rect1.x < rect2.x and rect1.y < rect2.y then – Lower Left
rect1.rotation = ((math.atan(yDif/xDif)) * 180/math.pi) - 90
end
end
[/lua]
Is there a way to simplify this or make it shorter?