Hello, I am trying to achive a rotation function that, whenever user clicks to a place on screen, the little circle in the middle of the screen rotates to that direction. What I can not do is, I can not determine the direction of the rotation.
Below is my code. what I want to do is, I want the circle to rotate with the closest path and does not make a full circle to go to a location.
Also another problem I am having is with the rotation values, as far as I know on math, the 90 degrees should point upwards, but when I use player.rotation = 90 it shows the 270* and looks downwards. any ideas.
if (event.phase == "began") then
local yPos = player.y - event.y
local xPos = player.x - event.x
rotationAngle = math.deg((math.atan2(yPos,xPos))) + 180
print("Rot Angle ".. rotationAngle .." / Player Rotation ".. player.rotation)
--transition.to(player, {time=500, rotation = rotationAngle })
elseif (event.phase == "ended") then
print(math.abs(-rotationAngle - player.rotation))
if (math.abs(rotationAngle - player.rotation) \<= 180 ) then
print("Small")
player:rotate(rotationAngle)
--transition.to(player, {time=500, rotation = rotationAngle })
elseif(math.abs(rotationAngle - player.rotation) \> 180) then
print("big")
player:rotate(-rotationAngle)
--transition.to(player, {time=500, rotation = rotationAngle })
end
--player.rotation = -rotationAngle
return true
end
[import]uid: 73033 topic_id: 26205 reply_id: 326205[/import]