# Help me in calculating the right edge of imagelabel with anchorpoint 0.5,0.5

local image = script.Parent.CanvasGroup.Straightline – Anchorpoint is 0.5,0.5
local heartfolder = script.Parent.CanvasGroup.Heartbeat – Just a folder

local function positioning(angle)

-- Line1
local line1 = image:Clone()  -- Anchorpoint is 0.5,0.5
line1.Parent = heartfolder
line1.Rotation = angle
line1.ImageTransparency = 0

-- Center position of line1
local midX = line1.Position.X.Scale
local midY = line1.Position.Y.Scale

-- Size of line1
local halfWidth = line1.Size.X.Scale / 2
local halfHeight = line1.Size.Y.Scale / 2

-- Calculating the corner position of line1
local cornerX = midX + halfWidth
local cornerY = midY + halfHeight

local originX = cornerX - midX
local originY = cornerY - midY

-- Calculating the rotated position of the corner

-- Line2
local line2 = image:Clone()  -- Anchorpoint is 0.5,0.5
line2.Parent = heartfolder
line2.Name = "Line2"
line2.ImageTransparency = 0

-- Set the position of line2 at the rotated corner position
line2.Position = UDim2.new(rotatedX + halfWidth, 0, rotatedY + halfHeight, 0)

end

wait(5)
positioning(45) – Example with a 45-degree angle

– This is the script. I checked Forum and found a useful one, but still I am messing up so I used ChatGpt for the problem. But still failed please help me.

What are you trying to exactly achieve? are you trying to get vector2/Udim position or some kind of region in right edge?

I want to calculate line1 's right edge at any rotation and place line2 on the calculated right edge.

Still little confused, could you possibly draw in paint the approximite visualization…?

This one shows rotation to 180. But I want to identify original (means when rotation was 0)right edge of any angles. Sorry for waiting.

Looks like I will never find my answer . Thanks you CDFII to try to help me.

Sorry, I forgot that devforum existed.

So what I understood, is that you want to keep the original point after image is rotated.
You can create variable when image is added and store the point.
local point = ImageLabel.Size.X / 2 If my math head remembers corectly, this should give you rightedge. if not, then you can do local point = ImageLabel.Size.X / -2 or something like that.
Also, remember to store the variable outside the fucntion, otherwise it’ll be update as the function is called

Hopefully this will explain.

Can you explain me more precisely?

Well, theres few ways to do this:

1. If your putting ui in that point, you can set the ui elements properties to these:
• AnchorPoint = {0.5, 0}{0.5, 0}
• Position = {0, 0}{0.5, 0}
• Parent = x X being the main ui which is being rotated
1. Second option is to use code (Quite bad regarding the performance):
local frame = script.Parent
local IND = Instance.new("Frame")
IND.Size = UDim2.fromOffset(20, 20)
IND.BackgroundColor3 = Color3.new(0.78, 0, 0)
IND.AnchorPoint = Vector2.new(0.5, 0.5)
IND.Parent = frame
IND.Visible = true

local point = frame.Size.X.Scale / 2

frame:GetPropertyChangedSignal("Rotation"):Connect(function()
IND.Position = UDim2.fromScale(point, 0.5)
end)

(You get almost same result from both above)
IND is just to show position. Actually necessary part is the:

local frame = script.Parent
local point = frame.Size.X.Scale / 2

You can test this using new UIDragDetector option in studio.

Hopefully this is what you are looking for. Personal suggestion is to use 1. since it’s good regarding the performance and also if you’re duplicating the same object, the settings stay same.

1 Like

As a follow up, the script which you got from ChatGPT, is full garbage. You don’t need to do fancy high school math (radians, corner calculation, etc.) to do this. Next time use deform for these kind of questions and issues.

Okay, I still confused with first method. Sorry for being too stupid to understand. Thanks for the advice of the trash Gpt.