Drawing lines/paths from pointA to pointB is offset

I am working on creating a simple line/path editor module but it isn’t going too well. Every time I calculate the angle, position and scale, it always is offset on the y axis. Here is an image of what I mean:


Capture2

Here is the function for calculating everything:

function path:draw()
	if p1 and p2 and loc then
		local screenSize = workspace.CurrentCamera.ViewportSize
		local startX = p1.X.Scale*screenSize.X
		local startY = p1.Y.Scale*screenSize.Y
		local endX = p2.X.Scale*screenSize.X
		local endY = p2.Y.Scale*screenSize.Y
		
		local size = UDim2.new(0, sqrt((endX - startX)^2 + (endY - startY)^2), 0.01)
		local pos = UDim2.new(0, (endX + startX)*0.5, 0, (endY + startY)*0.5)
		local angle = atan2(endY - startY, endX - startX)*(180/pi)
		
		local line = Instance.new("Frame")
		line.AnchorPoint = Vector2.new(0.5, 0.5)
		line.Position = pos
		line.Size = size
		line.Rotation = angle
		line.Parent = loc
	end
end

There are other posts related to this, but all of their solutions didn’t work even when I copied and pasted their code into mine (and changed it slightly to make it run with my setup). I have tried using scale and offset, both yield the same result.

Any help is greatly appreciated!

1 Like

Try replacing the pos variable’s value with

UDim2.fromOffset((endX - startX)/2 + startX, (endY - startY)/2 + startY)

If the line’s still offset, make sure loc’s position is at 0, 0.

1 Like

Didn’t work, gave the same results. Thank you though.