Hello devs!
I was trying to do one system and i got one problem:
I have no idea how get this position, i mean if it dont have rotation i can just make it like
local RightUpOffsetPos = gui.AbsolutePosition+Vector2.new(gui.AbsoluteSize.X,0)
This question interested me so I decided to look into it for 'ya. It took a bit of research but I was able to come up with this formula:
local frame = game.StarterGui.ScreenGui.Frame -- your UI object
local midX, midY = frame.AbsolutePosition.X + (frame.AbsoluteSize.X / 2), frame.AbsolutePosition.Y + (frame.AbsoluteSize.Y / 2) -- centre point of X and Y
local angle = frame.Rotation -- this is the rotation of the frame
local cornerX, cornerY = midX + (frame.AbsoluteSize.X / 2), midY + (frame.AbsoluteSize.Y / 2) -- the corner you are trying to get the position of, this is before factoring in the orientation. change the + to - to change between corners
local originX = cornerX - midX -- distance from 0,0
local originY = cornerY - midY
local rX = (originX * math.cos(math.rad(angle))) - (originY * math.sin(math.rad(angle))) -- new X factoring in rotation. note we need the angle to be in radians, not degrees.
local rY = (originX * math.sin(math.rad(angle))) + (originY * math.cos(math.rad(angle)))
local newCorner = Instance.new('Frame') -- new frame that will be created at the corner
newCorner.Size = UDim2.new(0,5,0,5)
newCorner.AnchorPoint = Vector2.new(0.5,0.5)
newCorner.Parent = frame.Parent
newCorner.Position = UDim2.new(0,rX + midX,0,rY + midY)
@7z99 Has a great response, but I also want to throw out there that you might be able to solve your particular problem by setting the AnchorPoint of your label to 1,0βthat way you can position the frame based on that corner.
Yeah, only problem is that you would only be able to get the position of that one corner whereas my script should work for all 4 corners, given you know the centre point of the UI object.