I can't think of a way to explain it. I'm basically taking two points and connecting them using a GUI Frame. It's working for the most part, but it gets off course in it's X dimension more and more as I move the points away in their Y dimension.
The names of the functions in this snippet should explain what they do, I just don't want to paste a lot of code if not needed. If you think it's an issue with one of them, though, I'd be more than happy to paste the functions.
local m = {}; m.AbsolutePosition = Vector2.new(0,0); game:GetService("RunService").RenderStepped:connect(function() m.AbsolutePosition = Vector2.new(mouse.X,mouse.Y); connector.Size = UDim2.new(0,getDistance(a.AbsolutePosition,m.AbsolutePosition),0,connectorWidth); connector.Position = UDim2.new(0,getLeftMost(a.AbsolutePosition,m.AbsolutePosition).X,0,(a.AbsolutePosition.Y+m.AbsolutePosition.Y)/2); connector.Rotation = getAngleTo(a.AbsolutePosition,m.AbsolutePosition) * (180/math.pi); end)
Here's a GIF of what it's doing.
This is what I use for drawing lines in 2D
function drawLine(p1, p2, parent) local v = (p2 - p1); -- vector between p2 and p1 local frame = Instance.new("Frame", parent); frame.BorderSizePixel = 0; frame.BackgroundColor3 = Color3.new(0, 1, 0); frame.Size = UDim2.new(0, v.magnitude, 0, 1); -- set the length to that of the difference frame.Rotation = math.deg(math.atan2(v.y, v.x)); -- get the angle between the two points frame.Position = UDim2.new(0, (p1.x + v.x/2) - frame.Size.X.Offset/2, 0, (p1.y + v.y/2) - frame.Size.Y.Offset/2); -- position from the center b/c that's where frames rotate from return frame; end;
The two key things to remember are tan(theta) = opposite/adjacent, then rearrange. The other thing is to position from the center because that's where gui objects rotate from.