9_Spy
(Spy)
March 21, 2023, 4:24pm
#1
I have been trying to connect two points in a UI with a line but cant seem to get the X offset right. Any ideas?
My code:
local Line = Dot2.Line
local Distance = (Dot2.AbsolutePosition - Dot1.AbsolutePosition)
local OriginPos = getOriginAbs(Line)
local Center = (Dot1.AbsolutePosition + Dot2.AbsolutePosition)/2
Line.Rotation = math.deg(math.atan2(Distance.Y,Distance.X))
Line.Visible = true
Line.Size = UDim2.new(0, Distance.Magnitude, 0, 2)
Line.Position = UDim2.fromOffset(Center.X, Center.Y) - UDim2.fromOffset(OriginPos.X, OriginPos.Y)
What I currently have:
quakage
(quakage)
March 21, 2023, 4:31pm
#2
Definitely try an internet search first. You will find this many times if you do. Here is one of them:
I’m a little late to the party but,
I also just want to note, the rotation of ‘atan2((y1-y2),(x1-x2))’ should be converted to degrees with the ‘math.deg()’ function. Took me way to long to figure that out
Anyway, I made a simple function to draw a line between 2 points using the logic @scotch101tape said (Point A and Point B should be Vector2’s in pixels from the top left corner of the screen, aka the AbsolutePosition of a UI object)
local function DrawLine(PointA, PointB, Parent)
local Dist…
9_Spy
(Spy)
March 21, 2023, 4:32pm
#3
I already looked through a lot of posts including that one but it didn’t seem the work on my script
quakage
(quakage)
March 21, 2023, 9:35pm
#4
Can you show how you called the DrawLine function within your code. Maybe I can see what you did wrong?
Fimutsuu
(Fimutsu)
March 21, 2023, 10:21pm
#5
try this for the OriginPos
local OriginPos = Dot2.AbsolutePosition - Dot2.AbsoluteSize/2
i just set it to Dot2’s absolute position since its the parent and remove half its size to center it
It looks like the positions are the position of the TextLabel
rather than the dot.
9_Spy
(Spy)
March 24, 2023, 4:25pm
#8
the dot is the parent and i never asked for the position of the textlabel in the script also when i test on mobile it is not on the position of the textlabel
9_Spy
(Spy)
March 24, 2023, 4:25pm
#9
i was able to fix it for all devices by multiplying it by 1.4206 something but i don’t know why this number works