Hi,
I am orbiting in a circle, I am trying to keep my player perpendicular to the circle of my orbit.
I calculate the points of my circle and use enterframe to update my position.
The problem is when I transition from -179 to 179 degrees my player does a 360 degree flip which looks really bad… I need to somehow eliminate this 360!
Any help greatly appreciated, Greg
enter frame code:
if int <= # orbit-1 then
local rotation =getImageRotation(player.x, player.y, orbit[int+1][1],orbit[int+1][2])
transition.to( player, { rotation = rotation+70, time=200, transition=easing.linear } )
mte.moveSpriteTo({sprite = player, levelPosX =orbit[int][1], levelPosY = orbit[int][2], time = 100, })
int = int + 1
else
int = 1
end
calculate image rotation based on two points
function getImageRotation(x1,y1,x2,y2)
local PI = 3.14159265358
local deltaY = y2 - y1
local deltaX = x2 - x1
local angleInDegrees = (math.deg(math.atan2( (y2-y1), (x2-x1))))
print (“ANGLE:”… angleInDegrees)
– local angleInDegrees = (math.atan2( deltaY, deltaX) * 180 / PI)
– local mult = 10^0
– return math.floor (angleInDegrees * mult + 0.5) / mult
return angleInDegrees
end