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:
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!