Currently there is a player object that rotates on a pivot depending on where you tap on the screen. This works correctly and it will choose the correct angle to transition to.

I have set it so the top half of the players rotational value goes from 0 to -180 and the bottom half 0 to 180. This results in the left side having a jump from 180 to -180, therefore the player object moves all the way around its pivot.

I have also tested it with having the bottom half go from 0 - 180 and then it continues on the top half going from 181 - 360 degrees. This results in the same issue but on the right side where the angle goes from 360 to 0 degrees.

I'm wondering if there is a decent way to fix this problem are it's visually quite annoying. Thanks

I took a gyazo gif screenshot showing a visual example of my problem:

https://gyazo.com/7635a8347758cb4e260be6d4a8021232

Below is my code which is responsible for handling the rotation of the player object. It's a mixture of my own code and bits that I've read from other forum posts.

local function getImageRotation(x1,y1,x2,y2) local PI = 3.14159265358 local deltaY = y2 - y1 local deltaX = x2 - x1 local angleInDegrees = (math.atan2( deltaY, deltaX) * 180 / PI) * -1 local mult = 10^0 return math.floor(angleInDegrees * mult + 0.5) / mult end ------------------------------------------------- local function onTravel(mouseX, mouseY) local function Flag() travelFlag = true --Fires a bullet in the direction of the player facing fireBullet() end if travelFlag then local newAngle = (getImageRotation(Player.pGroup.x,Player.pGroup.y,mouseX,mouseY))*-1 print("Angle = " .. newAngle) travelFlag = false transition.to( Player.pGroup, { time=500, rotation = newAngle, onComplete=Flag } ) end end ------------------------------------------------- local function beginRotate( event ) local phase = event.phase local t = event.target if phase == "began" then onTravel(event.x, event.y) end end