Advertisement
StefanBashkir

ROBLOX-GUI -> DrawLine (Supports Rotation Property)

Mar 1st, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. local StartPoint = script.Parent.StartPoint.AbsolutePosition;
  2. local EndPoint = script.Parent.EndPoint.AbsolutePosition;
  3.  
  4. function DrawLine(Start, End, Width)
  5.     local Start_O, End_O = Start, End
  6.     if (Start.X > End.X) then
  7.         End = Start_O
  8.         Start = End_O
  9.     end
  10.     local Line = Instance.new("Frame");
  11.     local XSize = (End-Start).magnitude;
  12.     local XDistance = (End.X-Start.X);
  13.     local YDistance = (End.Y-Start.Y);
  14.     local DesiredAngle = math.atan2(YDistance,XDistance);
  15.     local YPositionOffset = YDistance/2;
  16.     local XOffset = (1 - math.cos(DesiredAngle)) * (XSize/2)
  17.    
  18.     print("Distances :: " .. XDistance .. ", " .. YDistance);
  19.     print("Needed angle :: " .. math.deg(DesiredAngle));
  20.     Line.Rotation = math.deg(DesiredAngle);
  21.     Line.BorderSizePixel = 0;
  22.     Line.Size = UDim2.new(0,XSize,0,Width);
  23.     Line.Position = UDim2.new(0,Start.X-XOffset,0,Start.Y + YPositionOffset);
  24.     Line.Parent = script.Parent
  25.     print("Distance between GUIs :: " .. XSize);
  26.     return Line;
  27. end
  28.  
  29. DrawLine(StartPoint,EndPoint,2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement