Advertisement
scriptingtales

Roblox Angular Test

Jul 17th, 2023 (edited)
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.93 KB | None | 0 0
  1.  
  2. --Converted with ttyyuu12345's model to script plugin v4
  3. function sandbox(var,func)
  4.     local env = getfenv(func)
  5.     local newenv = setmetatable({},{
  6.         __index = function(self,k)
  7.             if k=="script" then
  8.                 return var
  9.             else
  10.                 return env[k]
  11.             end
  12.         end,
  13.     })
  14.     setfenv(func,newenv)
  15.     return func
  16. end
  17. cors = {}
  18. mas = Instance.new("Model",game:GetService("Lighting"))
  19. Folder0 = Instance.new("Folder")
  20. Folder1 = Instance.new("Folder")
  21. LocalScript2 = Instance.new("LocalScript")
  22. SelectionBox3 = Instance.new("SelectionBox")
  23. ModuleScript4 = Instance.new("ModuleScript")
  24. ModuleScript5 = Instance.new("ModuleScript")
  25. ModuleScript6 = Instance.new("ModuleScript")
  26. ModuleScript7 = Instance.new("ModuleScript")
  27. ModuleScript8 = Instance.new("ModuleScript")
  28. Folder9 = Instance.new("Folder")
  29. Script10 = Instance.new("Script")
  30. Folder11 = Instance.new("Folder")
  31. RemoteEvent12 = Instance.new("RemoteEvent")
  32. RemoteEvent13 = Instance.new("RemoteEvent")
  33. Script14 = Instance.new("Script")
  34. Folder0.Name = "You may see this folder but this is for a test!"
  35. Folder0.Parent = mas
  36. Folder1.Name = "StarterCharacterScripts"
  37. Folder1.Parent = Folder0
  38. LocalScript2.Name = "Tutorial"
  39. LocalScript2.Parent = Folder1
  40. LocalScript2.Enabled = false
  41. table.insert(cors,sandbox(LocalScript2,function()
  42. local p = game:GetService("Players").LocalPlayer
  43. local m = p:GetMouse()
  44. local cam = workspace.CurrentCamera
  45.  
  46. local selObj = nil
  47. local camCframe = nil
  48. local oS = nil
  49. local coolnessOffset = Vector3.new()
  50.  
  51. local function canMove(ob)
  52.     return ob.Name == "Object"
  53. end
  54.  
  55. local function getCP(r, p)
  56.     local rO, D = r.Origin - p, r.Direction
  57.     return rO - ( rO:Dot(D)/D:Dot(D) ) * D
  58. end
  59.  
  60. local function angleBetween(v1, v2)
  61.     return math.acos(v1:Dot(v2)/(v1.magnitude * v2.magnitude))
  62. end
  63.  
  64.  
  65. local e = game:GetService("ReplicatedStorage").UpdPhys
  66. local u = game:GetService("ReplicatedStorage").US
  67. local rr = require(script:WaitForChild("RotatedRegion3"))
  68.  
  69. m.Button1Down:Connect(function()
  70.     if m.Target and canMove(m.Target) then
  71.         m.Target.CanCollide = false
  72.         camCframe = cam.CFrame:ToObjectSpace(m.Target.CFrame)
  73.         oS = m.Target.Size
  74.         coolnessOffset = -getCP(m.UnitRay, m.Target.Position)
  75.         e:FireServer(m.Target)
  76.         --m.Target.Anchored = true
  77.         m.Target.Velocity = Vector3.new()
  78.         m.Target.RotVelocity = Vector3.new()
  79.         selObj = m.Target
  80.     end
  81. end)
  82.  
  83. m.Button1Up:Connect(function()
  84.     if selObj then
  85.         --selObj.Anchored = false
  86.         selObj.CanCollide = true
  87.         e:FireServer(m.Target)
  88.     end
  89.     selObj = nil
  90. end)
  91.  
  92. game:GetService("RunService").RenderStepped:Connect(function(dt)
  93.     coolnessOffset = coolnessOffset:Lerp(Vector3.new(), 0.2)
  94. end)
  95.  
  96. game:GetService("RunService").RenderStepped:Connect(function(dt)
  97.     if selObj then
  98.         selObj.CFrame = cam.CFrame:ToWorldSpace(camCframe)
  99.         local ray = Ray.new(cam.CFrame.p, cam.CFrame.LookVector * 1000)
  100.         local _, p, n = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent, selObj})
  101.         local dist = ((cam.CFrame.p - p).magnitude - selObj.Size.magnitude / 2) * -math.cos(angleBetween(ray.Direction, n))
  102.        
  103.         selObj.Size = (oS * dist / camCframe.p.magnitude)
  104.         selObj.Position = cam.CFrame.p + cam.CFrame.LookVector * dist
  105.        
  106.         for i = 1, 0, -0.01 do
  107.             local R = rr.fromPart(selObj)
  108.             if #R:cast({script.Parent, selObj}, 1) > 0 then
  109.                 dist = dist * i
  110.                 selObj.Size = (oS * dist / camCframe.p.magnitude)
  111.                 selObj.Position = cam.CFrame.p + cam.CFrame.LookVector * dist
  112.             else
  113.                 break
  114.             end
  115.         end
  116.        
  117.         u:FireServer(selObj, selObj.Size, selObj.CFrame)
  118.            
  119.         selObj.Position = selObj.Position + coolnessOffset
  120.     end
  121. end)
  122. end))
  123. LocalScript2.Disabled = true
  124. SelectionBox3.Parent = LocalScript2
  125. SelectionBox3.Visible = false
  126. SelectionBox3.Color = BrickColor.new("Institutional white")
  127. SelectionBox3.Color3 = Color3.new(1, 1, 1)
  128. SelectionBox3.LineThickness = 0.009999999776482582
  129. SelectionBox3.SurfaceColor = BrickColor.new("Really black")
  130. SelectionBox3.SurfaceColor3 = Color3.new(0, 0, 0)
  131. ModuleScript4.Name = "RotatedRegion3"
  132. ModuleScript4.Parent = LocalScript2
  133. table.insert(cors,sandbox(ModuleScript4,function()
  134. --[[
  135. This rotated region3 module is a bit different than the one I previously wrote. This uses GJK to do the collision calculations and
  136. as such does not calculate the minimum translation vector. In addition it does not calculate the intersection points anymore either.
  137. I don't think that had much place in a rotated region3 module.
  138.  
  139. As far as new features the module now supports a vast array of shapes and point clouds meaning more accurate collision!
  140.  
  141. API:
  142.  
  143. Constructors:
  144.     region.new(cframe, size)
  145.         > Creates a region from a cframe which acts as the center of the region and size which extends to
  146.         > the corners like a block part.
  147.     region.block(cframe, size)
  148.         > This is the exact same as the region.new constructor, but has a different name.
  149.     region.wedge(cframe, size)
  150.         > Creates a region from a cframe which acts as the center of the region and size which extends to
  151.         > the corners like a wedge part.
  152.     region.cornerWedge(cframe, size)
  153.         > Creates a region from a cframe which acts as the center of the region and size which extends to
  154.         > the corners like a cornerWedge part.
  155.     region.cylinder(cframe, size)
  156.         > Creates a region from a cframe which acts as the center of the region and size which extends to
  157.         > the corners like a cylinder part.
  158.     region.ellipsoid(cframe, size)
  159.         > Creates a region from a cframe which acts as the center of the region and size which extends to
  160.         > the corners like a ball part.
  161.     region.pointCloud(cloud)
  162.         > Creates a region from a table of points. The region is treated as a convex 3D shape when doing the collision detections.
  163.     region.fromPart(part)
  164.         > Creates a region from a part in the game. It can be used on any base part, but the region
  165.         > will treat unknown shapes (meshes, unions, etc) as block shapes.
  166.  
  167. Methods:
  168.     region:cast(ignore instance or table (descendants as well), int maxParts)
  169.         > returns a table full of parts that are inside the region
  170.     region:castPart(basePart)
  171.         > returns a boolean as to whether or not a given part is within a region or not
  172.     region:castPoint(vector3)
  173.         > returns a boolean as to whether or not a given point is within a region or not
  174.    
  175. Properties:
  176.     region.CFrame
  177.         > cframe that represents the center of the region
  178.     region.Size
  179.         > vector3 that represents the size of the region
  180. --]]
  181.  
  182. local gjk = require(script:WaitForChild("gjk"));
  183. local support = require(script:WaitForChild("supports"));
  184. local vertices = require(script:WaitForChild("vertices"));
  185. local draw = require(script:WaitForChild("draw"));
  186.  
  187. local region3 = {};
  188. local region3_mt = {__index = region3};
  189.  
  190. -- private functions
  191.  
  192. local type = type;
  193. local unpack = unpack;
  194. local insert = table.insert;
  195. local R3 = Region3.new;
  196.  
  197. local v3 = Vector3.new;
  198.  
  199. local function centroid(t)
  200.     local sum = t[1] - t[1];
  201.     for i = 1, #t do sum = sum + t[i]; end;
  202.     return sum / #t;
  203. end;
  204.  
  205. local function classify(part)
  206.     if (part.ClassName == "Part") then
  207.         if (part.Shape == Enum.PartType.Block) then
  208.             return region3.block(part.CFrame, part.Size);
  209.         elseif (part.Shape == Enum.PartType.Cylinder) then
  210.             return region3.cylinder(part.CFrame, part.Size);
  211.         elseif (part.Shape == Enum.PartType.Ball) then
  212.             return region3.ellipsoid(part.CFrame, part.Size);
  213.         end;
  214.     elseif (part.ClassName == "WedgePart") then
  215.         return region3.wedge(part.CFrame, part.Size);
  216.     elseif (part.ClassName == "CornerWedgePart") then
  217.         return region3.cornerWedge(part.CFrame, part.Size);
  218.     elseif (part:IsA("BasePart")) then -- mesh, CSG, truss, etc... just use block
  219.         return region3.block(part.CFrame, part.Size);
  220.     end;
  221. end;
  222.  
  223. -- public static functions
  224.  
  225. function region3.new(cf, size)
  226.     local self = {};
  227.     self.CFrame = cf;
  228.     self.Size = size;
  229.     self.input = {vertices.block(cf, size * 0.5, {})};
  230.     self.support = support.pointCloud;
  231.     self.centroid = cf.p;
  232.     return setmetatable(self, region3_mt);
  233. end;
  234.  
  235. region3.block = region3.new;
  236.  
  237. function region3.wedge(cf, size)
  238.     local self = {};
  239.     self.CFrame = cf;
  240.     self.Size = size;
  241.     self.input = {vertices.wedge(cf, size * 0.5, {})};
  242.     self.support = support.pointCloud;
  243.     self.centroid = centroid(self.input[1]);
  244.     return setmetatable(self, region3_mt);
  245. end;
  246.  
  247. function region3.cornerWedge(cf, size)
  248.     local self = {};
  249.     self.CFrame = cf;
  250.     self.Size = size;
  251.     self.input = {vertices.cornerWedge(cf, size * 0.5, {})};
  252.     self.support = support.pointCloud;
  253.     self.centroid = centroid(self.input[1]);
  254.     return setmetatable(self, region3_mt);
  255. end;
  256.  
  257. function region3.cylinder(cf, size)
  258.     local self = {};
  259.     self.CFrame = cf;
  260.     self.Size = size;
  261.     self.input = {cf, size * 0.5};
  262.     self.support = support.cylinder;
  263.     self.centroid = cf.p;
  264.     return setmetatable(self, region3_mt);
  265. end;
  266.  
  267. function region3.ellipsoid(cf, size)
  268.     local self = {};
  269.     self.CFrame = cf;
  270.     self.Size = size;
  271.     self.input = {cf, size * 0.5};
  272.     self.support = support.ellipsoid;
  273.     self.centroid = cf.p;
  274.     return setmetatable(self, region3_mt);
  275. end;
  276.  
  277. function region3.pointCloud(cloud)
  278.     local self = {};
  279.     self.CFrame = CFrame.new(centroid(cloud));
  280.     self.Size = v3();
  281.     self.input = cloud;
  282.     self.support = support.pointCloud;
  283.     self.centroid = self.CFrame.p;
  284.     return setmetatable(self, region3_mt);
  285. end;
  286.  
  287. function region3.fromPart(part)
  288.     return classify(part);
  289. end;
  290.  
  291. -- public methods
  292.  
  293. function region3:castPoint(point)
  294.     local direction = self.centroid - point;
  295.     return gjk(self.input, {point}, self.support, support.point, direction);
  296. end;
  297.  
  298. function region3:castPart(part)
  299.     local against = classify(part);
  300.     local direction = self.centroid - against.centroid;
  301.     return gjk(self.input, against.input, self.support, against.support, direction);
  302. end;
  303.  
  304. function region3:cast(ignore, maxParts)
  305.     local ignore = type(ignore) == "table" and ignore or {ignore};
  306.     local maxParts = maxParts or 20;
  307.    
  308.     local min, max = {}, {};
  309.     for _, enum in next, {Enum.NormalId.Right, Enum.NormalId.Top, Enum.NormalId.Back} do
  310.         local direction = Vector3.FromNormalId(enum);
  311.         insert(min, self.support(-direction, unpack(self.input)));
  312.         insert(max, self.support(direction, unpack(self.input)));
  313.     end;
  314.     min, max = v3(min[1].x, min[2].y, min[3].z), v3(max[1].x, max[2].y, max[3].z);
  315.    
  316.     local allignedR3 = R3(min, max);
  317.     local parts = game.Workspace:FindPartsInRegion3WithIgnoreList(allignedR3, ignore, maxParts);
  318.    
  319.     -- debug stuff
  320.     --game.Workspace.CurrentCamera:ClearAllChildren();
  321.     --draw.line(min, max, game.Workspace.CurrentCamera);
  322.    
  323.     local inRegion = {};
  324.     for i = 1, #parts do
  325.         local part = parts[i];
  326.         if (self:castPart(part)) then
  327.             insert(inRegion, part);
  328.         end;
  329.     end;
  330.     return inRegion;
  331. end;
  332.  
  333. -- return module
  334.  
  335. return region3;
  336. end))
  337. ModuleScript5.Name = "gjk"
  338. ModuleScript5.Parent = ModuleScript4
  339. table.insert(cors,sandbox(ModuleScript5,function()
  340. local v3 = Vector3.new;
  341. local dot = v3().Dot;
  342. local cross = v3().Cross;
  343.  
  344. local unpack = unpack;
  345. local insert = table.insert;
  346. local remove = table.remove;
  347.  
  348. local function tripleProduct(a, b, c)
  349.     -- (a x b) x c = b * (c . a) - a * (c . b)
  350.     return b * dot(c, a) - a * dot(c, b);
  351. end;
  352.  
  353. local function containsOrigin(simplex, direction)
  354.     local a = simplex[#simplex];
  355.     local a0 = -a;
  356.     if (#simplex == 4) then
  357.         local b, c, d = simplex[3], simplex[2], simplex[1];
  358.         local ba, ca, da = b - a, c - a, d - a;
  359.         local abc = cross(ba, ca);
  360.         local adb = cross(da, ba);
  361.         local acd = cross(ca, da);
  362.         abc = dot(abc, da) > 0 and -abc or abc;
  363.         adb = dot(adb, ca) > 0 and -adb or adb;
  364.         acd = dot(acd, ba) > 0 and -acd or acd;
  365.         if (dot(abc, a0) > 0) then
  366.             remove(simplex, 1);
  367.             direction = abc;
  368.         elseif (dot(adb, a0) > 0) then
  369.             remove(simplex, 2);
  370.             direction = adb;
  371.         elseif (dot(acd, a0) > 0) then
  372.             remove(simplex, 3);
  373.             direction = acd;
  374.         else
  375.             return true;
  376.         end;
  377.     elseif (#simplex == 3) then
  378.         local b, c = simplex[2], simplex[1];
  379.         local ba, ca = b - a, c - a;
  380.         local baPerp, caPerp = tripleProduct(ca, ba, ba), tripleProduct(ba, ca, ca);
  381.         if (dot(baPerp, a0) > 0) then
  382.             remove(simplex, 1);
  383.             direction = baPerp;
  384.         elseif (dot(caPerp, a0) > 0) then
  385.             remove(simplex, 2);
  386.             direction = caPerp;
  387.         else
  388.             local abc = ba:Cross(ca);
  389.             if (dot(abc, a0) == 0) then return true; end;
  390.             direction = (dot(abc, a0) > 0) and abc or -abc;
  391.         end;
  392.     else
  393.         local b = simplex[1];
  394.         local ba = b - a;
  395.         direction = tripleProduct(ba, a0, ba);
  396.     end;
  397.     return false, direction;
  398. end;
  399.  
  400. local function collision(A, B, supportA, supportB, direction)
  401.     local simplex = {supportA(direction, unpack(A)) - supportB(-direction, unpack(B))};
  402.     direction = -direction;
  403.     while (true) do
  404.         insert(simplex, supportA(direction, unpack(A)) - supportB(-direction, unpack(B)));     
  405.         if (dot(simplex[#simplex], direction) < 0) then
  406.             return false;
  407.         else
  408.             local pass, newDirection = containsOrigin(simplex, direction);
  409.             if (pass) then return true; end;
  410.             direction = newDirection;
  411.         end;
  412.     end;
  413. end;
  414.  
  415. return collision;
  416.  
  417. end))
  418. ModuleScript6.Name = "supports"
  419. ModuleScript6.Parent = ModuleScript4
  420. table.insert(cors,sandbox(ModuleScript6,function()
  421. -- support functions for GJK
  422. -- Ego
  423.  
  424. local v3 = Vector3.new;
  425. local dot = v3().Dot;
  426.  
  427. local cos = math.cos;
  428. local sin = math.sin;
  429. local min = math.min;
  430. local abs = math.abs;
  431. local huge = math.huge;
  432. local sqrt = math.sqrt;
  433. local atan2 = math.atan2;
  434.  
  435. local AXIS = v3(1, 0, 0);
  436. local ORIGIN = v3(0, 0, 0);
  437.  
  438. -- math functions
  439.  
  440. local function rayPlane(p, v, s, n)
  441.     local r = p - s;
  442.     local t = -dot(r, n) / dot(v, n);
  443.     return p + t * v, t;
  444. end;
  445.  
  446. -- support functions
  447.  
  448. local function point(direction, p)
  449.     return p;
  450. end;
  451.  
  452. local function pointCloud(direction, cloud)
  453.     local max, maxProj = nil, -huge;
  454.     for i = 1, #cloud do
  455.         local proj = dot(cloud[i], direction)
  456.         if (proj > maxProj) then
  457.             max = cloud[i];
  458.             maxProj = proj;
  459.         end;
  460.     end;
  461.     return max;
  462. end;
  463.  
  464. local function cylinder(direction, cf, size)
  465.     direction = cf:vectorToObjectSpace(direction);
  466.     local radius = min(size.y, size.z);
  467.     local dotT, cPoint = dot(direction, AXIS), v3(size.x, 0, 0);
  468.     local h, t, final;
  469.     if (dotT == 0) then
  470.         final = direction.unit * radius;
  471.     else
  472.         cPoint = dotT > 0 and cPoint or -cPoint;
  473.         h, t = rayPlane(ORIGIN, direction, cPoint, AXIS);
  474.         local diff = h - cPoint;
  475.         if (diff.magnitude > radius) then
  476.             diff = diff.unit * radius;
  477.         end;
  478.         final = cPoint + diff;
  479.     end;
  480.     return cf:pointToWorldSpace(final);
  481. end;
  482.  
  483. local function ellipsoid(direction, cf, size)
  484.     direction = cf:vectorToObjectSpace(direction)
  485.     local p0 = (size * direction).unit;
  486.     return cf:pointToWorldSpace(size*p0);
  487. end
  488.  
  489. return {
  490.     pointCloud = pointCloud;
  491.     cylinder = cylinder;
  492.     ellipsoid = ellipsoid;
  493.     point = point;
  494. };
  495. end))
  496. ModuleScript7.Name = "draw"
  497. ModuleScript7.Parent = ModuleScript4
  498. table.insert(cors,sandbox(ModuleScript7,function()
  499. -- 3D drawing functions
  500. -- contains a few basic 3D shapes that are useful when testing, etc
  501. -- EgoMoose
  502.  
  503. local wedge = Instance.new("WedgePart");
  504. wedge.Anchored = true;
  505. wedge.TopSurface = Enum.SurfaceType.Smooth;
  506. wedge.BottomSurface = Enum.SurfaceType.Smooth;
  507.  
  508. local part = Instance.new("Part");
  509. part.Size = Vector3.new(0.1, 0.1, 0.1);
  510. part.Anchored = true;
  511. part.TopSurface = Enum.SurfaceType.Smooth;
  512. part.BottomSurface = Enum.SurfaceType.Smooth;
  513. part.Material = Enum.Material.Neon;
  514.  
  515. local function drawPoint(p, parent)
  516.     local point = part:Clone();
  517.     point.CFrame = CFrame.new(p);
  518.     point.BrickColor = BrickColor.Blue();
  519.     point.Parent = parent;
  520.     return point;
  521. end;
  522.  
  523. local function drawLine(a, b, parent)
  524.     local v = (b - a);
  525.     local cf = CFrame.new(a + v * 0.5, b);
  526.     local line = part:Clone();
  527.     line.CFrame = cf;
  528.     line.Size = Vector3.new(0.1, 0.1, v.magnitude);
  529.     line.BrickColor = BrickColor.Red();
  530.     line.Parent = parent;
  531.     return line;
  532. end
  533.  
  534. local function drawTriangle(a, b, c, parent, transparency)
  535.     local edges = {
  536.         {longest = (c - b), other = (a - b), position = b};
  537.         {longest = (a - c), other = (b - c), position = c};
  538.         {longest = (b - a), other = (c - a), position = a};
  539.     };
  540.     table.sort(edges, function(a, b) return a.longest.magnitude > b.longest.magnitude end);
  541.     local edge = edges[1];
  542.     local theta = math.acos(edge.longest.unit:Dot(edge.other.unit));
  543.     local s1 = Vector2.new(edge.other.magnitude * math.cos(theta), edge.other.magnitude * math.sin(theta));
  544.     local s2 = Vector2.new(edge.longest.magnitude - s1.x, s1.y);
  545.     local p1 = edge.position + edge.other * 0.5;
  546.     local p2 = edge.position + edge.longest + (edge.other - edge.longest) * 0.5;
  547.     local right = edge.longest:Cross(edge.other).unit;
  548.     local up = right:Cross(edge.longest).unit;
  549.     local back = edge.longest.unit;
  550.     local cf1 = CFrame.new(
  551.         p1.x, p1.y, p1.z,
  552.         -right.x, up.x, back.x,
  553.         -right.y, up.y, back.y,
  554.         -right.z, up.z, back.z
  555.     );
  556.     local cf2 = CFrame.new(
  557.         p2.x, p2.y, p2.z,
  558.         right.x, up.x, -back.x,
  559.         right.y, up.y, -back.y,
  560.         right.z, up.z, -back.z
  561.     );
  562.     local w1 = wedge:Clone();
  563.     local w2 = wedge:Clone();
  564.     w1.Size = Vector3.new(0.2, s1.y, s1.x);
  565.     w2.Size = Vector3.new(0.2, s2.y, s2.x);
  566.     w1.Transparency = transparency or 0;
  567.     w2.Transparency = transparency or 0;
  568.     w1.CFrame = cf1;
  569.     w2.CFrame = cf2;
  570.     w1.Parent = parent;
  571.     w2.Parent = parent;
  572. end;
  573.  
  574. return {
  575.     triangle = drawTriangle;
  576.     point = drawPoint;
  577.     line = drawLine;
  578. };
  579. end))
  580. ModuleScript8.Name = "vertices"
  581. ModuleScript8.Parent = ModuleScript4
  582. table.insert(cors,sandbox(ModuleScript8,function()
  583. -- calculate corners and points on shape
  584. -- useful for a lot of 3D math, eg convex hull, GJK, etc.
  585. -- EgoMoose
  586.  
  587. local cos = math.cos;
  588. local sin = math.sin;
  589. local insert = table.insert;
  590.  
  591. local cornerMultipliers = {
  592.     Vector3.new(1, 1, 1);
  593.     Vector3.new(1, 1, -1);
  594.     Vector3.new(1, -1, -1);
  595.     Vector3.new(-1, -1, -1);
  596.     Vector3.new(-1, -1, 1);
  597.     Vector3.new(-1, 1, 1);
  598.     Vector3.new(-1, 1, -1);
  599.     Vector3.new(1, -1, 1);
  600. }
  601.  
  602. -- the functions that get the vertices
  603.  
  604. local function block(cf, size, t)
  605.     for i = 1, #cornerMultipliers do
  606.         insert(t, cf * (size * cornerMultipliers[i]));
  607.     end
  608.     return t;
  609. end;
  610.  
  611. local WEDGE = {1, 3, 4, 5, 6, 8};
  612. local function wedge(cf, size, t)
  613.     for i = 1, #WEDGE do
  614.         insert(t, cf * (size * cornerMultipliers[WEDGE[i]]));
  615.     end;
  616.     return t;
  617. end;
  618.  
  619. local CORNERWEDGE = {2, 3, 4, 5, 8};
  620. local function cornerWedge(cf, size, t)
  621.     for i = 1, #CORNERWEDGE do
  622.         insert(t, cf * (size * cornerMultipliers[CORNERWEDGE[i]]));
  623.     end;
  624.     return t;
  625. end;
  626.  
  627. local PI2 = math.pi * 2;
  628. local function cylinder(cf, size, t, amt)
  629.     local amt = amt or 10;
  630.     local div = PI2 / amt;
  631.     local c1, c2 = cf * (size * Vector3.new(1, 0, 0)), cf * (size * Vector3.new(-1, 0, 0));
  632.     local up, axis = cf * (size * Vector3.new(1, 1, 0)) - c1, (c1 - cf.p).unit;
  633.     for i = 1, amt do
  634.         local theta = div * i;
  635.         -- vector axis angle rotation
  636.         local v = up * cos(theta) + up:Dot(axis) * axis * (1 - cos(theta)) + axis:Cross(up) * sin(theta);
  637.         insert(t, c1 + v);
  638.         insert(t, c2 + v);
  639.     end;
  640.     return t;
  641. end;
  642.  
  643. local function ball(cf, size, t, amt1, amt2)
  644.     local right, forward, up = cf.rightVector * size.x, cf.lookVector * size.z, cf.upVector * size.y;
  645.     local amt1, amt2 = amt1 or 8, amt2 or 8;
  646.     local div1, div2 = PI2 / amt1, PI2 / amt2;
  647.     for i = 1, amt1 do
  648.         local theta = i * div1;
  649.         local horizontal = forward * cos(theta) + right * sin(theta);
  650.         for j = 1, amt2 do
  651.             local theta2 = j * div2;
  652.             local p = cf.p + horizontal * cos(theta2) + up * sin(theta2);
  653.             insert(t, p)
  654.         end;
  655.     end;
  656.     return t;
  657. end;
  658.  
  659. -- special functions
  660.  
  661. local function getAllVertices(parts, t)
  662.     local t = t or {};
  663.     for i = 1, #parts do
  664.         local part = parts[i];
  665.         if (part.ClassName == "Part") then
  666.             if (part.Shape == Enum.PartType.Block) then
  667.                 block(part.CFrame, part.Size*0.5, t);
  668.             elseif (part.Shape == Enum.PartType.Cylinder) then
  669.                 cylinder(part.CFrame, part.Size*0.5, t);
  670.             elseif (part.Shape == Enum.PartType.Ball) then
  671.                 ball(part.CFrame, part.Size*0.5, t);
  672.             end;
  673.         elseif (part.ClassName == "WedgePart") then
  674.             wedge(part.CFrame, part.Size*0.5, t);
  675.         elseif (part.ClassName == "CornerWedgePart") then
  676.             cornerWedge(part.CFrame, part.Size*0.5, t);
  677.         elseif (part:IsA("BasePart")) then -- mesh, CSG, truss, etc... just use block
  678.             block(part.CFrame, part.Size*0.5, t);
  679.         end;
  680.     end;
  681.     return t;
  682. end;
  683.  
  684. -- module
  685.  
  686. return {
  687.     block = block;
  688.     wedge = wedge;
  689.     cornerWedge = cornerWedge;
  690.     cylinder = cylinder;
  691.     ball = ball;
  692.     getAllVertices = getAllVertices;
  693. };
  694. end))
  695. Folder9.Name = "ServerScriptService"
  696. Folder9.Parent = Folder0
  697. Script10.Parent = Folder9
  698. table.insert(cors,sandbox(Script10,function()
  699. game:GetService("ReplicatedStorage").UpdPhys.OnServerEvent:Connect(function(p, obj)
  700.     if obj.Name == "Object" and (not obj:FindFirstChild("Dragger")) then
  701.         local oj = Instance.new("ObjectValue")
  702.         oj.Name = "Dragger"
  703.         oj.Value = p
  704.         oj.Parent = obj
  705.         obj:SetNetworkOwner(p)
  706.         obj.Anchored = true
  707.         obj.CanCollide = false
  708.     elseif obj.Dragger and obj.Dragger.Value == p then
  709.         obj.Dragger:Destroy()
  710.         --obj:SetNetworkOwner(nil)
  711.         obj.Velocity = Vector3.new()
  712.         obj.RotVelocity = Vector3.new()
  713.         obj.Anchored = false
  714.         obj.CanCollide = true
  715.     end
  716. end)
  717.  
  718. game:GetService("ReplicatedStorage").US.OnServerEvent:Connect(function(p, obj, s, po)
  719.     obj.Size = s
  720.     obj.CFrame = po
  721. end)
  722. end))
  723. Folder11.Name = "ReplicatedStorage"
  724. Folder11.Parent = Folder0
  725. RemoteEvent12.Name = "US"
  726. RemoteEvent12.Parent = Folder11
  727. RemoteEvent13.Name = "UpdPhys"
  728. RemoteEvent13.Parent = Folder11
  729. Script14.Name = "EnablerPutter"
  730. Script14.Parent = Folder0
  731. table.insert(cors,sandbox(Script14,function()
  732. local ScriptSer = script.Parent.ServerScriptService.Script
  733. local Replic, Replic2 = script.Parent.ReplicatedStorage.US, script.Parent.ReplicatedStorage.UpdPhys
  734. local Tutor = script.Parent.StarterCharacterScripts.Tutorial
  735.  
  736.  
  737.  
  738. ScriptSer.Parent = game.ServerScriptService
  739. Replic.Parent = game.ReplicatedStorage
  740. Replic2.Parent = Replic.Parent
  741. Tutor.Parent = game.StarterPlayer.StarterCharacterScripts
  742.  
  743. if not Tutor.Enabled then
  744.     local en = Tutor.Enabled
  745. end
  746. end))
  747. for i,v in pairs(mas:GetChildren()) do
  748.     v.Parent = workspace
  749.     pcall(function() v:MakeJoints() end)
  750. end
  751. mas:Destroy()
  752. for i,v in pairs(cors) do
  753.     spawn(function()
  754.         pcall(v)
  755.     end)
  756. end
  757.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement