Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local setupPart = function(part)
- part.Anchored = true
- part.FormFactor = 'Custom'
- part.CanCollide = true
- part.BrickColor = BrickColor.new()
- part.TopSurface = 'Smooth'
- part.BottomSurface = 'Smooth'
- local m = Instance.new("SpecialMesh",part)
- m.MeshType = "Wedge"
- m.Scale = Vector3.new(0,1,1)
- return part
- end
- function CFrameFromTopBack(at, top, back)
- local right = top:Cross(back)
- return CFrame.new(at.x, at.y, at.z, right.x, top.x, back.x, right.y, top.y, back.y, right.z, top.z, back.z)
- end
- function CreateTriangle(parent, a, b, c)
- local this = {}
- local mPart1 = Instance.new('WedgePart')
- setupPart(mPart1)
- local mPart2 = Instance.new('WedgePart')
- setupPart(mPart2)
- function this:Set(a, b, c)
- local ab, bc, ca = b-a, c-b, a-c
- local abm, bcm, cam = ab.magnitude, bc.magnitude, ca.magnitude
- local edg1 = math.abs(0.5 + ca:Dot(ab)/(abm*abm))
- local edg2 = math.abs(0.5 + ab:Dot(bc)/(bcm*bcm))
- local edg3 = math.abs(0.5 + bc:Dot(ca)/(cam*cam))
- if edg1 < edg2 then
- if edg1 < edg3 then
- a, b, c = c, a, b ab, bc, ca = ca, ab, bc abm = cam
- elseif edg2 < edg3 then
- a, b, c = b, c, a
- ab, bc, ca = bc, ca, ab
- abm = bcm
- else
- a, b, c = c, a, b ab, bc, ca = ca, ab, bc abm = cam
- end
- end
- local len1 = -ca:Dot(ab)/abm
- local len2 = abm - len1
- local width = (ca + ab.unit*len1).magnitude
- local maincf = CFrameFromTopBack(a, ab:Cross(bc).unit, -ab.unit)
- if len1 > 0.2 then
- mPart1.Parent = parent mPart1.Size = Vector3.new(0.2, width, len1)
- mPart1.CFrame = maincf*CFrame.Angles(math.pi,0,math.pi/2)*CFrame.new(0,width/2,len1/2)
- else
- mPart1.Parent = nil
- end
- if len2 > 0.2 then
- mPart2.Parent = parent
- mPart2.Size = Vector3.new(0.2, width, len2)
- mPart2.CFrame = maincf*CFrame.Angles(math.pi,math.pi,-math.pi/2)*CFrame.new(0,width/2,-len1 - len2/2)
- else
- mPart2.Parent = nil
- end
- end
- function this:SetProperty(prop, value)
- mPart1[prop] = value
- mPart2[prop] = value
- end
- this:Set(a, b, c)
- function this:Destroy()
- mPart1:Destroy()
- mPart2:Destroy()
- end
- return this
- end
- local t = {}
- local vertices = {}
- Mouse = game.Players.LocalPlayer:GetMouse()
- Player = game.Players.LocalPlayer
- local N = Instance.new("Part",Player.Character)
- N.Anchored = true
- N.FormFactor = "Custom"
- N.Size = Vector3.new(0.4,0.4,0.4)
- N.TopSurface = "Smooth"
- N.BottomSurface = "Smooth"
- TarP = Mouse.Hit.p
- Off = CFrame.new(0,0,0)
- X,Y,Z = 0,0,0
- On = true
- Mouse.Button1Down:connect(function()
- if On then
- local P = N:clone()
- P.Parent = Player.Character
- P.CFrame = CFrame.new(TarP)
- table.insert(t,{Part=P,CF=TarP})
- if #t >= 3 then
- local n = {}
- for i,v in pairs(t) do
- table.insert(vertices,v.CF)
- n[i]=v.CF
- v.Part:Destroy()
- end
- CreateTriangle(Workspace,unpack(n))
- t = {}
- end
- end
- end)
- Mouse.Move:connect(function()
- if On then
- local p = Mouse.Hit.p
- local pos = p
- for i,v in pairs(vertices) do
- if (p-v).magnitude < 0.5 then
- pos = v
- end
- end
- TarP = (CFrame.new(pos)*CFrame.Angles(math.rad(X),math.rad(Y),math.rad(Z))*Off).p
- end
- end)
- Mouse.KeyDown:connect(function(k)
- if k == "r" then -- up
- Off = Off+Vector3.new(0,1,0)
- end
- if k == "f" then -- down
- Off = Off-Vector3.new(0,1,0)
- end
- if k == "m" then
- X,Y,Z = 0,0,0
- Off = CFrame.new(0,0,0)
- end
- if k == "z" then
- X = X+10
- end
- if k == "x" then --|Rotation
- Z = Z+10
- end
- --[[if k == "c" then
- Z = Z+10
- end]]
- if k == "q" then
- On = not On
- end
- end)
- game:GetService("RunService").RenderStepped:connect(function()
- N.CFrame = CFrame.new(TarP)
- N.Parent = On and Player.Character or nil
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement