How to calculate right edge of imagelabel of 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
local radian = math.rad(angle)
local rotatedX = originX * math.cos(radian) - originY * math.sin(radian)
local rotatedY = originX * math.sin(radian) + originY * math.cos(radian)

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

add the half of the x width of its position to get the edge position

Where to add the X- half width in the script?

idk how would I do cause your script also accounts for rotation

Ooh, then I should go and do more research until othesr help me in this problem. Btw thanks gor trying to help me.

Upper link is about similar thing I want, it helped the guy who asked the question. When I tried it, it didn’t work for me. You should see it and that may give you some idea what is wrong with my script.

1 Like