Advertisement
Gametoy

cape r15

Feb 16th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. local verlet = {}
  2. verlet.step_time = 1 / 50
  3. verlet.gravity = Vector3.new(0, -10, 0)
  4.  
  5. local char = game.Players.LocalPlayer.Character
  6. local torso = char:WaitForChild("UpperTorso")
  7. local parts = {}
  8. local render = game:GetService("RunService").RenderStepped
  9. local part = Transperancy == ".8"
  10.  
  11. wait(2)
  12.  
  13. local point = {}
  14. local link = {}
  15. local rope = {}
  16.  
  17. local function ccw(A,B,C)
  18. return (C.y-A.y) * (B.x-A.x) > (B.y-A.y) * (C.x-A.x)
  19. end
  20.  
  21. local function intersect(A,B,C,D)
  22. return ccw(A,C,D) ~= ccw(B,C,D) and ccw(A,B,C) ~= ccw(A,B,D)
  23. end
  24.  
  25. local function vec2(v)
  26. return Vector2.new(v.x, v.z)
  27. end
  28.  
  29. function point:step()
  30. if not self.fixed then
  31. local derivative = (self.position - self.last_position) * 0.80
  32. self.last_position = self.position
  33. self.position = self.position + derivative + (self.velocity * verlet.step_time ^ 2)
  34. local torsoP = torso.CFrame * CFrame.new(-1, 0, 0.5)
  35. local torsoE = torso.CFrame * CFrame.new(1, 0, 0.5)
  36. local pointE = self.position + torso.CFrame.lookVector * 100
  37. local doIntersect = intersect(vec2(torsoP.p), vec2(torsoE.p), vec2(self.position), vec2(pointE))
  38. if not doIntersect then
  39. self.postition = self.position - torso.CFrame.lookVector * 10
  40. end
  41. end
  42. end
  43.  
  44. function link:step()
  45. for i = 1, 1 do
  46. local distance = self.point1.position - self.point2.position
  47. local magnitude = distance.magnitude
  48. local differance = (self.length - magnitude) / magnitude
  49. local translation = ((self.point1.fixed or self.point2.fixed) and 1 or 0.6) * distance * differance
  50. if not self.point1.fixed then
  51. self.point1.position = self.point1.position + translation
  52. end
  53. if not self.point2.fixed then
  54. self.point2.position = self.point2.position - translation
  55. end
  56. end
  57. end
  58.  
  59. function verlet.new(class, a, b, c)
  60. if class == "Point" then
  61. local new = {}
  62. setmetatable(new, {__index = point})
  63. new.class = class
  64. new.position = a or Vector3.new()
  65. new.last_position = new.position
  66. new.velocity = verlet.gravity
  67. new.fixed = false
  68. return new
  69. elseif class == "Link" then
  70. local new = {}
  71. setmetatable(new, {__index = link})
  72. new.class = class
  73. new.point1 = a
  74. new.point2 = b
  75. new.length = c or (a.position - b.position).magnitude
  76. return new
  77. elseif class == "Rope" then
  78. local new = {}
  79. setmetatable(new, {__index = link})
  80. new.class = class
  81. new.start_point = a
  82. new.finish_point = b
  83. new.points = {}
  84. new.links = {}
  85. local inc = (b - a) / 10
  86. for i = 0, 10 do
  87. table.insert(new.points, verlet.new("Point", a + (i * inc)))
  88. end
  89. for i = 2, #new.points do
  90. table.insert(new.links, verlet.new("Link", new.points[i - 1], new.points[i]))
  91. end
  92. return new
  93. end
  94. end
  95.  
  96. local tris = {}
  97. local triParts = {}
  98.  
  99. local function GetDiscoColor(hue)
  100. local section = hue % 1 * 3
  101. local secondary = 0.5 * math.pi * (section % 1)
  102. if section < 1 then
  103. return Color3.new(1, 1 - math.cos(secondary), 1 - math.sin(secondary))
  104. elseif section < 2 then
  105. return Color3.new(1 - math.sin(secondary), 1, 1 - math.cos(secondary))
  106. else
  107. return Color3.new(1 - math.cos(secondary), 1 - math.sin(secondary), 1)
  108. end
  109. end
  110.  
  111. local function setupPart(part)
  112. part.Anchored = true
  113. part.FormFactor = 3
  114. part.CanCollide = false
  115. part.TopSurface = 10
  116. part.BottomSurface = 10
  117. part.LeftSurface = 10
  118. part.RightSurface = 10
  119. part.FrontSurface = 10
  120. part.BackSurface = 10
  121. part.Material = "Glass"
  122. local m = Instance.new("SpecialMesh", part)
  123. m.MeshType = "Wedge"
  124. m.Scale = Vector3.new(0.2, 1, 1)
  125. return part
  126. end
  127.  
  128. local function CFrameFromTopBack(at, top, back)
  129. local right = top:Cross(back)
  130. 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)
  131. end
  132.  
  133. local function drawTri(parent, a, b, c)
  134. local this = {}
  135. local mPart1 = table.remove(triParts, 1) or setupPart(Instance.new("Part"))
  136. local mPart2 = table.remove(triParts, 1) or setupPart(Instance.new("Part"))
  137. function this:Set(a, b, c)
  138. local ab, bc, ca = b-a, c-b, a-c
  139. local abm, bcm, cam = ab.magnitude, bc.magnitude, ca.magnitude
  140. local edg1 = math.abs(0.5 + ca:Dot(ab)/(abm*abm))
  141. local edg2 = math.abs(0.5 + ab:Dot(bc)/(bcm*bcm))
  142. local edg3 = math.abs(0.5 + bc:Dot(ca)/(cam*cam))
  143. if edg1 < edg2 then
  144. if edg1 >= edg3 then
  145. a, b, c = c, a, b
  146. ab, bc, ca = ca, ab, bc
  147. abm = cam
  148. end
  149. else
  150. if edg2 < edg3 then
  151. a, b, c = b, c, a
  152. ab, bc, ca = bc, ca, ab
  153. abm = bcm
  154. else
  155. a, b, c = c, a, b
  156. ab, bc, ca = ca, ab, bc
  157. abm = cam
  158. end
  159. end
  160.  
  161. local len1 = -ca:Dot(ab)/abm
  162. local len2 = abm - len1
  163. local width = (ca + ab.unit*len1).magnitude
  164.  
  165. local maincf = CFrameFromTopBack(a, ab:Cross(bc).unit, -ab.unit)
  166.  
  167. if len1 > 0.2 then
  168. mPart1.Parent = parent
  169. mPart1.Size = Vector3.new(0.2, width, len1)
  170. mPart1.CFrame = maincf*CFrame.Angles(math.pi,0,math.pi/2)*CFrame.new(0,width/2,len1/2)
  171. else
  172. mPart1.Parent = nil
  173. end
  174.  
  175. if len2 > 0.2 then
  176. mPart2.Parent = parent
  177. mPart2.Size = Vector3.new(0.2, width, len2)
  178. mPart2.CFrame = maincf*CFrame.Angles(math.pi,math.pi,-math.pi/2)*CFrame.new(0,width/2,-len1 - len2/2)
  179. else
  180. mPart2.Parent = nil
  181. end
  182. end
  183. function this:SetProperty(prop, value)
  184. mPart1[prop] = value
  185. mPart2[prop] = value
  186. end
  187. this:Set(a, b, c)
  188. function this:Destroy()
  189. mPart1:Destroy()
  190. mPart2:Destroy()
  191. end
  192. this.p1 = mPart1
  193. this.p2 = mPart2
  194. this.p1.BrickColor = BrickColor.new(GetDiscoColor(math.noise(0.5, 0.5, this.p1.CFrame.Y * 0.5 + time())))
  195. this.p2.BrickColor = BrickColor.new(GetDiscoColor(math.noise(0.5, 0.5, this.p2.CFrame.Y * 0.5 + time())))
  196. return this
  197. end
  198.  
  199. function verlet.draw(object, id)
  200. if object.class == "Point" then
  201. local part = parts[id]
  202. part.BrickColor = BrickColor.new(1, 1, 1)
  203. part.Transparency = 1
  204. part.formFactor = 3
  205. part.Anchored = true
  206. part.CanCollide = false
  207. part.TopSurface = 0
  208. part.BottomSurface = 0
  209. part.Size = Vector3.new(0.35, 0.35, 0.35)
  210. part.Material = "Glass"
  211. part.CFrame = CFrame.new(object.position)
  212. part.Parent = torso
  213. return part
  214. elseif object.class == "Link" then
  215. local part = parts[id]
  216. local dist = (object.point1.position - object.point2.position).magnitude
  217. part.Size = Vector3.new(0.2, 0.2, dist)
  218. part.CFrame = CFrame.new(object.point1.position, object.point2.position) * CFrame.new(0, 0, dist * -0.5)
  219. part.Parent = torso
  220. return part
  221. end
  222. end
  223.  
  224. function verlet.clear()
  225. for _, v in pairs(workspace:GetChildren()) do
  226. if v.Name == "Part" then
  227. v:Destroy()
  228. end
  229. end
  230. end
  231.  
  232. local points = {}
  233. local links = {}
  234.  
  235. for x = 0, 2 do
  236. points[x] = {}
  237. for y = 0, 3 do
  238. points[x][y] = verlet.new("Point", torso.Position + Vector3.new(x * 0.8 - 2, 2 - y * 0.8, 5 + y * 0.4))
  239. points[x][y].fixed = y == 0
  240. end
  241. end
  242.  
  243. for x = 1, 2 do
  244. for y = 0, 3 do
  245. links[#links + 1] = verlet.new("Link", points[x][y], points[x - 1][y], 1 + y * 0.08)
  246. end
  247. end
  248.  
  249. for x = 0, 2 do
  250. for y = 1, 3 do
  251. links[#links + 1] = verlet.new("Link", points[x][y], points[x][y - 1], 1.2 + y * 0.03)
  252. end
  253. end
  254.  
  255. render:connect(function()
  256. for x = 0, 2 do
  257. for y = 0, 3 do
  258. if y == 0 then
  259. points[x][y].position = (torso.CFrame * CFrame.new(x * 1 - 1, 1, 0.5)).p
  260. else
  261. points[x][y]:step()
  262. end
  263. end
  264. end
  265. for i = 1, #links do
  266. links[i]:step()
  267. end
  268. for i = 1, #tris do
  269. triParts[#triParts + 1] = tris[i].p1
  270. triParts[#triParts + 1] = tris[i].p2
  271. end
  272. tris = {}
  273. for x = 1, 2 do
  274. for y = 1, 3 do
  275. tris[#tris + 1] = drawTri(torso, points[x - 1][y - 1].position, points[x - 1][y].position, points[x][y - 1].position)
  276. tris[#tris + 1] = drawTri(torso, points[x][y].position, points[x - 1][y].position, points[x][y - 1].position)
  277. end
  278. end
  279. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement