Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to rotate GUI on a point?

Asked by 9 years ago

I'm looking to rotate a gui with a particular point acting as the center of rotation. Unfortunately I don't know how to go about doing this... Here's an image depicting the situation: http://i.imgur.com/xPkPbzL.jpg

Obligatory code:

function rotateFromPoint(gui, x,y, angle) --x,y being the point on the gui (0,0 being corner)
    --and here I haven't a clue how to offset the rotation point and all that jazz.
end

0
Good question I thought I saw a image before of a surface gui rotating from a point, I could be wrong though. GetSporked 5 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

If you took trigonometry, you would know that in a Unit Circle, the coordinate of any point on that circle is equal to (Cos(Angle),Sin(Angle)). "Angle" being the angle of the line drawn from (0,0) to the coordinate of the point. So in order to rotate a Gui around a point, you would have to code it like this:

function rotateFromPoint(Gui,X,Y,Angle,Radius)
    local XPos = X + math.cos(Angle) * Radius
    local YPos = Y + math.sin(Angle) * Radius
    Gui.Position = UDim2.new(0,XPos,0,YPos)
end

Hope this helped!

Note: XPos and YPos are going to be the offset values, not the scale values.

Link(s): Unit Circle

0
My bad, what I meant was "How to rotate a GUI on a point"( instead of from the center when using the Rotation property). However, this does do a good job at circling around the point, i'll keep this in mind. MrgamesNwatch 65 — 9y
Ad

Answer this question