Hello, I have checked the following post:
As said, I am trying to draw lines between two points. I have implemented this into my code and, well, it does not work.
for _, requirement in upgradeData.Requires do
local req = StarScroll:FindFirstChild(requirement)
DrawPath(script.line:Clone(), template, req)
end
On the bottom I am sharing an image of the hierachy & used code & problem.
local function DrawPath(Line, P1, P2)
local Size = workspace.CurrentCamera.ViewportSize
local startX, startY = P1.Position.X.Scale*Size.X, P1.Position.Y.Scale*Size.Y
local endX, endY = P2.Position.X.Scale*Size.X, P2.Position.Y.Scale*Size.Y
local startVector = Vector2.new(startX, startY)
local endVector = Vector2.new(endX, endY)
local Distance = (startVector - endVector).Magnitude
Line.AnchorPoint = Vector2.new(0.5, 0.5)
Line.Size = UDim2.new(0, Distance, 0, 5)
Line.Position = UDim2.new(0, (startX + endX) / 2, 0, (startY + endY) / 2)
Line.Rotation = math.atan2(endY - startY, endX - startX) * (180 / math.pi)
Line.Parent = StarScroll
end
As you can see, red arrows are what I am expecting and blue arrows are what is going on with said method & code.
Any help is appreciated, thanks!