Edge position of rotated gui

Hello devs!
I was trying to do one system and i got one problem:
Снимок экрана 2021-06-20 001914_LI
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)

But what to do if gui have rotation ~= 0

1 Like

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)

Screen Shot 2021-06-21 at 1.32.59 AM

local cornerX, cornerY = midX - (frame.AbsoluteSize.X / 2), midY + (frame.AbsoluteSize.Y / 2)

Screen Shot 2021-06-21 at 1.32.26 AM

@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.

1 Like

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.

1 Like

Thanks for help, but i already understanded how make this and just wanted for someone did some explanation lol.
Thats how i did this

RUP1 = ((G1.AbsolutePosition+G1.AbsoluteSize/2)+Vector2.new(math.cos(math.rad(G1.Rotation))*G1.AbsoluteSize.X/2,math.sin(math.rad(G1.Rotation))*G1.AbsoluteSize.X/2))+Vector2.new(math.cos(math.rad(G1.Rotation-90))*G1.AbsoluteSize.Y/2,math.sin(math.rad(G1.Rotation-90))*G1.AbsoluteSize.Y/2)
RDP1 = ((G1.AbsolutePosition+G1.AbsoluteSize/2)+Vector2.new(math.cos(math.rad(G1.Rotation))*G1.AbsoluteSize.X/2,math.sin(math.rad(G1.Rotation))*G1.AbsoluteSize.X/2))+Vector2.new(math.cos(math.rad(G1.Rotation+90))*G1.AbsoluteSize.Y/2,math.sin(math.rad(G1.Rotation+90))*G1.AbsoluteSize.Y/2)
LUP1 = ((G1.AbsolutePosition+G1.AbsoluteSize/2)+Vector2.new(math.cos(math.rad(G1.Rotation+180))*G1.AbsoluteSize.X/2,math.sin(math.rad(G1.Rotation+180))*G1.AbsoluteSize.X/2))+Vector2.new(math.cos(math.rad(G1.Rotation-90))*G1.AbsoluteSize.Y/2,math.sin(math.rad(G1.Rotation-90))*G1.AbsoluteSize.Y/2)
LDP1 = ((G1.AbsolutePosition+G1.AbsoluteSize/2)+Vector2.new(math.cos(math.rad(G1.Rotation+180))*G1.AbsoluteSize.X/2,math.sin(math.rad(G1.Rotation+180))*G1.AbsoluteSize.X/2))+Vector2.new(math.cos(math.rad(G1.Rotation+90))*G1.AbsoluteSize.Y/2,math.sin(math.rad(G1.Rotation+90))*G1.AbsoluteSize.Y/2)
1 Like