Advertisement
Ariya1234gamer

Triangle Module

Mar 31st, 2020
1,433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | None | 0 0
  1. local Triangle do
  2.     local v3 = Vector3.new
  3.     local cf = CFrame.new
  4.     local abs = math.abs
  5.     local cross = v3().Cross
  6.     local dot = v3().Dot
  7.     local clone = game.Clone
  8.    
  9.     local ref = Instance.new('WedgePart') do
  10.         ref.Color         = Color3.fromRGB(200, 200, 200)
  11.         ref.Material      = Enum.Material.SmoothPlastic
  12.         ref.Reflectance   = 0
  13.         ref.Transparency  = 0
  14.         ref.Name          = ""
  15.         ref.Anchored      = true
  16.         ref.CanCollide    = false
  17.         ref.CFrame        = cf()
  18.         ref.Size          = v3(0.25, 0.25, 0.25)
  19.         ref.BottomSurface = Enum.SurfaceType.Smooth
  20.         ref.TopSurface    = Enum.SurfaceType.Smooth
  21.     end
  22.    
  23.     local function fromAxes(p, x, y, z)
  24.         return cf(
  25.             p.x, p.y, p.z,
  26.             x.x, y.x, z.x,
  27.             x.y, y.y, z.y,
  28.             x.z, y.z, z.z
  29.         )
  30.     end
  31.    
  32.     function Triangle(a, b, c, parent, wb, wc, N)
  33.         local ab, ac, bc = b - a, c - a, c - b
  34.         local abl, acl, bcl = ab.magnitude, ac.magnitude, bc.magnitude
  35.         if abl > bcl and abl > acl then
  36.             c, a = a, c
  37.         elseif acl > bcl and acl > abl then
  38.             a, b = b, a
  39.         end
  40.         ab, ac, bc = b - a, c - a, c - b
  41.         local out = cross(ac, ab).unit
  42.         wb = wb or clone(ref)
  43.         wc = wc or clone(ref)
  44.         local biDir = cross(bc, out).unit
  45.         local biLen = abs(dot(ab, biDir))
  46.         local norm = bc.magnitude
  47.         wb.Size = v3(0, abs(dot(ab, bc))/norm, biLen)
  48.         wc.Size = v3(0, biLen, abs(dot(ac, bc))/norm)
  49.         bc = -bc.unit
  50.         wb.CFrame = fromAxes((a + b)/2, -out, bc, -biDir)
  51.         wc.CFrame = fromAxes((a + c)/2, -out, biDir, bc)
  52.         local G = Instance.new("Model", parent)
  53.         G.Name = "Floor" .. N
  54.         wb.Parent = G
  55.         wc.Parent = G
  56.         return wb, wc
  57.     end
  58. end
  59.  
  60. return Triangle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement