Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Plrs = game:GetService("Players")
- local LP = Plrs.LocalPlayer
- local mouse = LP:GetMouse()
- local cam = workspace.CurrentCamera
- --define *ideal* fragmentation sizing
- local fragX = 4
- local fragY = 8
- local fragZ = 1
- ------------------------------------
- local num = 0
- local offCFrames = {
- X = {
- ["Front"] = {true, false, false};
- ["Back"] = {true, false, false};
- ["Right"] = {false, false, true};
- ["Left"] = {false, false, true};
- ["Top"] = {false, false, true};
- ["Bottom"] = {false, false, true};
- };
- Y = {
- ["Front"] = {false, false, true};
- ["Back"] = {false, false, true};
- ["Right"] = {true, false, false};
- ["Left"] = {false, true, false};
- ["Top"] = {false, false, true};
- ["Bottom"] = {false, false, true};
- };
- Z = {
- ["Front"] = {false, false, true};
- ["Back"] = {false, false, true};
- ["Right"] = {true, false, false};
- ["Left"] = {true, false, false};
- ["Top"] = {false, true, false};
- ["Bottom"] = {false, true, false};
- }
- }
- local offSizes = {
- X = {
- ["Front"] = "x";
- ["Back"] = "x";
- ["Right"] = "z";
- ["Left"] = "z";
- ["Top"] = "x";
- ["Bottom"] = "x";
- };
- Y = {
- ["Front"] = "y";
- ["Back"] = "y";
- ["Right"] = "y";
- ["Left"] = "y";
- ["Top"] = "z";
- ["Bottom"] = "z";
- };
- Z = {
- ["Front"] = "z";
- ["Back"] = "z";
- ["Right"] = "x";
- ["Left"] = "x";
- ["Top"] = "y";
- ["Bottom"] = "y";
- }
- }
- local function makePart2(CF, Size, Obj)
- local Part = Instance.new("Part")
- Part.Name = "new" --Using real name causes object to act as a clone sometimes. May mess up proportions slight due to meshy stuff (E.g. in Arms)
- Part.Anchored = Obj.Anchored
- Part.CanCollide = Obj.CanCollide
- Part.TopSurface = "SmoothNoOutlines"
- Part.BottomSurface = "SmoothNoOutlines"
- Part.FrontSurface = "SmoothNoOutlines"
- Part.BackSurface = "SmoothNoOutlines"
- Part.LeftSurface = "SmoothNoOutlines"
- Part.RightSurface = "SmoothNoOutlines"
- Part.BrickColor = Obj.BrickColor
- Part.Transparency = Obj.Transparency
- Part.Material = Obj.Material
- Part.Size = Size
- Part.CFrame = CF
- if Part.CanCollide == false and Part.Anchored == false then
- Part.Anchored = true
- end
- Part.Parent = Obj.Parent
- return Part
- end
- local function getCF(Hit, Target, Surface, fromHit)
- local offsetCFrame = Target.CFrame
- if fromHit then
- local TargetAng = Target.CFrame - Target.CFrame.p
- offsetCFrame = CFrame.new(Hit.p) * TargetAng
- end
- if Surface == "Top" then
- offsetCFrame = offsetCFrame * CFrame.Angles(math.rad(-270), 0, 0)
- elseif Surface == "Bottom" then
- offsetCFrame = offsetCFrame * CFrame.Angles(math.rad(270), 0, 0)
- elseif Surface == "Front" then
- offsetCFrame = offsetCFrame
- elseif Surface == "Back" then
- offsetCFrame = offsetCFrame * CFrame.Angles(0, math.rad(180), 0)
- elseif Surface == "Left" then
- offsetCFrame = offsetCFrame * CFrame.Angles(0, math.rad(-270), 0)
- elseif Surface == "Right" then
- offsetCFrame = offsetCFrame * CFrame.Angles(0, math.rad(270), 0)
- end
- return offsetCFrame
- end
- mouse.Button1Down:connect(function()
- if mouse.Target then
- local hit = mouse.Hit
- local targ = mouse.Target
- local surf = mouse.TargetSurface
- surf = tostring(surf):sub(15)
- local hitCF = getCF(hit, targ, surf, true)
- local angCF = getCF(hit, targ, surf)
- local angPos = angCF.p
- local nowSizeX = targ.Size[offSizes.X[surf]]
- local nowSizeY = targ.Size[offSizes.Y[surf]]
- local nowSizeZ = targ.Size[offSizes.Z[surf]]
- local objSpace = angCF:toObjectSpace(hitCF)
- local DistX = objSpace.x
- local DistY = objSpace.y
- local DistZ = objSpace.z
- local nowCenterX = angCF * CFrame.new(DistX, 0, 0) --Hit cframe with only hit X
- local nowCenterY = angCF * CFrame.new(0, DistY, 0) --Hit cframe with only hit Y
- local nowCenterXY = angCF * CFrame.new(DistX, DistY, 0) --Hit cframe with only hit X and Y
- local rightCFX
- local rightSizeX
- local leftCFX
- local leftSizeX
- --RIGHT
- do
- local sizeX = math.max(((nowCenterX * CFrame.new((fragX/2), 0, 0)):toObjectSpace((angCF * CFrame.new((nowSizeX/2), 0, 0)))).x, 0.2)
- local sizeY = nowSizeY
- local cfX = (angCF:toObjectSpace((angCF * CFrame.new((nowSizeX/2), 0, 0)))).x - (sizeX/2)
- local cfY = 0
- rightCFX = cfX
- rightSizeX = sizeX
- local objSize = Vector3.new(sizeX, sizeY, nowSizeZ)
- local objCF = angCF * CFrame.new(cfX, cfY, 0)
- makePart2(objCF, objSize, targ)
- end
- --LEFT
- do
- local sizeX = math.max(((angCF * CFrame.new(-(nowSizeX/2), 0, 0)):toObjectSpace((nowCenterX * CFrame.new(-(fragX/2), 0, 0)))).x, 0.2)
- local sizeY = nowSizeY
- local cfX = (angCF:toObjectSpace((angCF * CFrame.new(-(nowSizeX/2), 0, 0)))).x + (sizeX/2)
- local cfY = 0
- leftCFX = cfX
- leftSizeX = sizeX
- local objSize = Vector3.new(sizeX, sizeY, nowSizeZ)
- local objCF = angCF * CFrame.new(cfX, cfY, 0)
- makePart2(objCF, objSize, targ)
- end
- local sideSizeX = (rightCFX - (rightSizeX/2)) - (leftCFX + (leftSizeX/2))
- local sideCFX = ((rightCFX - (rightSizeX/2)) + (leftCFX + (leftSizeX/2)))/2
- --TOP
- do
- local sizeX = sideSizeX
- local sizeY = math.max(((nowCenterY * CFrame.new(0, (fragY/2), 0)):toObjectSpace((angCF * CFrame.new(0, (nowSizeY/2), 0)))).y, 0.2)
- local cfX = sideCFX
- local cfY = (angCF:toObjectSpace((angCF * CFrame.new(0, (nowSizeY/2), 0)))).y - (sizeY/2)
- local objSize = Vector3.new(sizeX, sizeY, nowSizeZ)
- local objCF = angCF * CFrame.new(cfX, cfY, 0)
- makePart2(objCF, objSize, targ)
- end
- --BOTTOM
- do
- local sizeX = sideSizeX
- local sizeY = math.max(((angCF * CFrame.new(0, -(nowSizeY/2), 0)):toObjectSpace((nowCenterY * CFrame.new(0, -(fragY/2), 0)))).y, 0.2)
- local cfX = sideCFX
- local cfY = (angCF:toObjectSpace((angCF * CFrame.new(0, -(nowSizeY/2), 0)))).y + (sizeY/2)
- local objSize = Vector3.new(sizeX, sizeY, nowSizeZ)
- local objCF = angCF * CFrame.new(cfX, cfY, 0)
- makePart2(objCF, objSize, targ)
- end
- targ:Destroy()
- end
- end)
- --Right
- --SizeX: (ObjCFX + 1/2ObjWidth) - (MouseCFX + 1/2FragX)
- --SizeY: ObjSizeY
- --CFX: ObjCFX + 1/2ObjWidth - 1/2RightHeight
- --CFY: ObjCFY
- --Left
- --SizeX: (MouseCFX - 1/2FragX) - (ObjCFX - 1/2ObjWidth)
- --SizeY: ObjSizeY
- --CFX: ObjCFX - 1/2ObjWidth + 1/2RightHeight
- --CFY: ObjCFY
- --Top
- --SizeX: FragX
- --SizeY: (ObjCFY + 1/2ObjHeight) - (MouseCFY + 1/2FragY)
- --CFX: MouseCFX
- --CFY: ObjCFY + 1/2ObjHeight - 1/2TopHeight
- --Bottom
- --SizeX: FragX
- --SizeY: (MouseCFY - 1/2FragY) - (ObjCFY - 1/2ObjHeight)
- --CFX: MouseCFX
- --CFY: ObjCFY - 1/2ObjHeight + 1/2TopHeight
Add Comment
Please, Sign In to add comment