How can I make a line between 2 UDim2 positions? Similar like with CFrame, but I cant get this one working. Could you help me ;D ?
COMMUNITY QUESTION
How to make a line between 2 UDim2 positions?
1 answer
Try this:
-- @author Narrev
-- Draw a line between 2 UDim2 positions
-- Does not support Scale
local Position1 = UDim2.new(0,10,0,0)
local Position2 = UDim2.new(0,100,0,100)
local Line_Thickness = 2
local Parent = script.Parent
local function Draw(Position1, Position2)
local Distance_X, Distance_Y = Position2.X.Offset - Position1.X.Offset, Position2.Y.Offset - Position1.Y.Offset
local Distance = (Distance_X * Distance_X + Distance_Y * Distance_Y) ^ .5
local Angle = math.atan2(Distance_Y, Distance_X)
-- Create Line
local Line = Instance.new("Frame", Parent)
Line.Size = UDim2.new(0, Distance, 0, Line_Thickness)
local Center_X, Center_Y = 0.5 * (Position1.X.Offset + Position2.X.Offset), 0.5 * (Position1.Y.Offset + Position2.Y.Offset)
Line.Position = UDim2.new(0, Center_X - 0.5*Distance, 0, Center_Y - 0.5*Line_Thickness)
Line.Rotation = math.deg(Angle)
end
Draw(Position1, Position2)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Thank you, I didnt think about using atan for the rotation, ;)
No problem! Please accept answer if I helped!