Anyone familiar with CFrame.new(position, pointAtposition)
? It changes a part's position and look straight at another part. Now obviously CFrame.new
doesn't work with GUIs. A few months ago the Rotation property was introduced to GuiObjects
which rotates GUI's. Ok so the problem here is that I have no idea how to rotate a GUI towards a position on the screen (In pixels, not scale). I am making a game where when you click somewhere on the screen, a little GUI "plane" rotates towards it and move to the location. Also, would the rotation be entered as a normal number or with math.rad?
~Thank you
Basically, you want to calculate the angle between two arbitrary points on a 2D plane.
This code will do just that:
function getAngleInDegrees(point1, point2) point2 = point2 - point1 angle = math.atan2(point2.y, point2.x) return math.deg(angle) end
So, say, I had an Arrow ImageLabel I wanted to point towards a Frame.
ImageLabel.Rotation = getAngleInDegrees(ImageLabel.AbsolutePositon, Frame.AbsolutePosition)