Honestly, it’s quite hard to help without seeing some code. For example, the myGroup:rotate() function doesn’t do any transitioning for you, which leads me to believe you are using it in an enterFrame listener, but I can’t be sure. The reason why you are having more success with it than with setting the rotation value might be because the rotate() function adds myAngle to the current rotation, whereas setting the rotation value just sets the rotation of the group to myAngle, so they are doing two different things.
In any case, rotating to face a particular point is a tricky business. You need to account for whether the start rotation is bigger or smaller than the goal rotation and rotate in the appropriate direction. You also need to account for whether the difference between the two rotations is more or less than half a circle (180 degrees), which also affects which direction you need to rotate. The combination leads to four cases that you need to account for:
-
start rotation is less than end rotation, rotation difference < 180
-
start rotation is less than end rotation, rotation difference > 180
-
start rotation is greater than end rotation, rotation difference < 180
-
start rotation is greater than end rotation, rotation difference > 180
Like I said, tricky. Roaminggamer has offered a lot of help, but I understand that ssk can sometimes seem a bit complicated and overwhelming. Here’s a small sample project that may help you out:
local rect = display.newRect(display.contentCenterX, display.contentCenterY, 10, 1)
rect.anchorX = 0
local function normaliseRotation(r)
while r < 0 do r = r + 360
end
while r > 360 do r = r - 360
end
return r
end
local function rotateRect(e)
rect.rotation = normaliseRotation(rect.rotation)
local startRotation = rect.rotation
local endRotation = normaliseRotation(math.atan2(e.y - rect.y, e.x - rect.x)*180/math.pi)
local angleDiff
if startRotation < endRotation then
if math.abs(startRotation - endRotation) < 180 then angleDiff = endRotation - startRotation
else angleDiff = - (startRotation - endRotation + 360)
end
else
if math.abs(startRotation - endRotation) < 180 then angleDiff = endRotation - startRotation
else angleDiff = math.abs(endRotation + 360 - startRotation)
end
end
transition.to(rect, {rotation = startRotation + angleDiff, time = math.abs(angleDiff*5)})
end
Runtime:addEventListener("tap", rotateRect)