Currently, I am working on a project and within it, I have a conundrum. I’m attempting to draw a line in the form of a frame between an ImageLabel within a BillboardGUI and a part in the workspace (HumanoidRootPart). I’m aware of how to convert a Vector3 to UDim2 using WorldToScreenPoint, however, it still does not work properly. I was hoping some god-tier mathematicians could read over my code and see where I’m going wrong. The associated function is below, with all the necessary variable information provided. Any advice would be greatly appreciated, and before you say it, no, AbsolutePosition does not work.
--[[
TargetPart is the HumanoidRootPart
BaseHolder is the BillboardGUI
Point is an ImageLabel that I am using as one of the two origin points for the line
ConnectorPart is a Frame that I am using as the line to connect between two 2D points
]]--
local TargetPart = Character:WaitForChild("HumanoidRootPart")
local TargetPosition = CurrentCamera:WorldToScreenPoint(TargetPart.Position)
TargetPosition = UDim2.new(0, TargetPosition.X, 0, TargetPosition.Y)
local HolderPosition = CurrentCamera:WorldToScreenPoint(TargetPart.Position + BaseHolder.ExtentsOffset)
HolderPosition = UDim2.new(0, HolderPosition.X, 0, HolderPosition.Y)
local PointPosition = UDim2.new(0, Point.AbsolutePosition.X, 0, Point.AbsolutePosition.Y) + HolderPosition
ConnectorPart.Size = UDim2.fromOffset(
math.sqrt(
(PointPosition.X.Offset-TargetPosition.X.Offset)^2+(PointPosition.Y.Offset-TargetPosition.Y.Offset)^2
),
5
)
ConnectorPart.Position = UDim2.fromOffset(
(PointPosition.X.Offset+TargetPosition.X.Offset)/2, (PointPosition.Y.Offset+TargetPosition.Y.Offset)/2
)
ConnectorPart.Rotation = math.deg(
math.atan2(
(PointPosition.Y.Offset-TargetPosition.Y.Offset), (PointPosition.X.Offset-TargetPosition.X.Offset)
)
)
Again, any advice is welcome, my math skills aren’t the greatest, and this problem has been stressing me for hours, so it hasn’t helped with the math lol. Thanks in advance!