Advertisement
Team_Alex

Untitled

Mar 9th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.42 KB | None | 0 0
  1. PyramidCharacter = {};
  2.  
  3. local stock_triangle = Instance.new("WedgePart")
  4. stock_triangle.Anchored = true
  5. stock_triangle.BottomSurface = "Smooth"
  6. stock_triangle.FormFactor = "Custom"
  7. stock_triangle.Locked = true
  8. stock_triangle.TopSurface = "Smooth"
  9. local stock_triangle_mesh = Instance.new("SpecialMesh", stock_triangle)
  10. stock_triangle_mesh.MeshType = "Wedge"
  11. local triangles = {}
  12. function PyramidCharacter.CreateTriangle(v1, v2, v3, properties, parent, index)
  13. local triangleInfo = triangles[index]
  14. local side1 = (v1 - v2).magnitude
  15. local side2 = (v2 - v3).magnitude
  16. local side3 = (v3 - v1).magnitude
  17. local sqrside1 = side1 * side1
  18. local sqrside2 = side2 * side2
  19. local sqrside3 = side3 * side3
  20. if sqrside3 + sqrside1 == sqrside2 then
  21. v1, v2, v3 = v1, v2, v3
  22. elseif sqrside1 + sqrside2 == sqrside3 then
  23. v1, v2, v3 = v2, v3, v1
  24. elseif sqrside2 + sqrside3 == sqrside1 then
  25. v1, v2, v3 = v3, v1, v2
  26. elseif sqrside1 >= sqrside2 and sqrside1 >= sqrside3 then
  27. v1, v2, v3 = v1, v2, v3
  28. elseif sqrside2 >= sqrside3 and sqrside2 >= sqrside1 then
  29. v1, v2, v3 = v2, v3, v1
  30. else
  31. v1, v2, v3 = v3, v1, v2
  32. end
  33. local model, part1, part2, mesh1, mesh2
  34. if triangleInfo then
  35. model, part1, part2, mesh1, mesh2 = unpack(triangleInfo)
  36. if not (model.Parent == parent and part1.Parent == model and part2.Parent == model and mesh1.Parent == part1 and mesh2.Parent == part2) then
  37. if model.Parent then
  38. model:Destroy()
  39. end
  40. model = nil
  41. end
  42. else
  43. triangleInfo = {}
  44. triangles[index] = triangleInfo
  45. end
  46. if not model then
  47. model = Instance.new("Model")
  48. part1 = stock_triangle:Clone()
  49. part2 = stock_triangle:Clone()
  50. mesh1 = part1.Mesh
  51. mesh2 = part2.Mesh
  52. part1.Parent = model
  53. part2.Parent = model
  54. triangleInfo[1] = model
  55. triangleInfo[2] = part1
  56. triangleInfo[3] = part2
  57. triangleInfo[4] = mesh1
  58. triangleInfo[5] = mesh2
  59. end
  60. for key, value in pairs(properties) do
  61. part1[key] = value
  62. part2[key] = value
  63. end
  64. local cframe = CFrame.new(v1, v2)
  65. local relpos = cframe:pointToObjectSpace(v3)
  66. cframe = cframe * CFrame.fromEulerAnglesXYZ(0, 0, -math.atan2(relpos.x, relpos.y))
  67. local rel1 = cframe:pointToObjectSpace(v1)
  68. local rel2 = cframe:pointToObjectSpace(v2)
  69. local rel3 = cframe:pointToObjectSpace(v3)
  70. local height = rel3.y
  71. local width1 = rel3.z
  72. local width2 = rel2.z - rel3.z
  73. local relcenter1 = Vector3.new(0, height / 2, width1 / 2)
  74. local center1 = cframe:pointToWorldSpace(relcenter1)
  75. local relcenter2 = Vector3.new(0, height / 2, width2 / 2 + width1)
  76. local center2 = cframe:pointToWorldSpace(relcenter2)
  77. height = math.abs(height)
  78. width1 = math.abs(width1)
  79. width2 = math.abs(width2)
  80. if not part1.Anchored then
  81. part1.Anchored = true
  82. end
  83. part1.Size = Vector3.new(0.2, height, width1)
  84. part1.CFrame = cframe * CFrame.fromEulerAnglesXYZ(0, math.pi, 0) - cframe.p + center1
  85. mesh1.Scale = Vector3.new(0, height / part1.Size.y, width1 / part1.Size.z)
  86. if not part2.Anchored then
  87. part2.Anchored = true
  88. end
  89. part2.Size = Vector3.new(0.2, height, width1)
  90. part2.CFrame = cframe - cframe.p + center2
  91. mesh2.Scale = Vector3.new(0, height / part1.Size.y, width2 / part2.Size.z)
  92. model.Parent = parent
  93. return model
  94. end
  95. PyramidCharacter.head_properties = {BrickColor = BrickColor.new(Color3.new(1, 1, 1)), Transparency = 0.5}
  96. PyramidCharacter.head_radius = math.pi
  97. PyramidCharacter.center = CFrame.new(0, 10, 0)
  98. PyramidCharacter.point1 = Vector3.new()
  99. PyramidCharacter.point2 = Vector3.new()
  100. PyramidCharacter.point3 = Vector3.new()
  101. PyramidCharacter.point4 = Vector3.new()
  102. PyramidCharacter.core_mesh_scale = Vector3.new(0.833, 0.833, 0.833)
  103. PyramidCharacter.visible = false
  104. function PyramidCharacter.Teleport(location)
  105. PyramidCharacter.point1 = location
  106. PyramidCharacter.point2 = location
  107. PyramidCharacter.point3 = location
  108. PyramidCharacter.point4 = location
  109. end
  110. local stock_core = Instance.new("Part")
  111. stock_core.Anchored = true
  112. stock_core.BottomSurface = "Smooth"
  113. stock_core.Color = Color3.new(1, 1, 1)
  114. stock_core.FormFactor = "Custom"
  115. stock_core.Locked = true
  116. stock_core.Name = "CubePyramid"
  117. stock_core.Size = Vector3.new(0.5, 0.5, 0.5)
  118. stock_core.TopSurface = "Smooth"
  119. PyramidCharacter.stock_core = stock_core
  120. PyramidCharacter.core = stock_core:Clone()
  121. PyramidCharacter.Archivable = false
  122. PyramidCharacter.core_mesh = Instance.new("BlockMesh", core)
  123. PyramidCharacter.core_lights = {}
  124. PyramidCharacter.coreLightCount = 1
  125. for index = 1, PyramidCharacter.coreLightCount do
  126. PyramidCharacter.core_lights[index] = Instance.new("PointLight", core)
  127. end
  128. PyramidCharacter.camera_distance = (Camera.Focus.p - Camera.CoordinateFrame.p).magnitude
  129. PyramidCharacter.camera_position = Vector3.new()
  130. Camera.Changed:connect(function(property)
  131. if PyramidCharacter.visible then
  132. if property == "CoordinateFrame" then
  133. local cframe, focus = Camera.CoordinateFrame, Camera.Focus
  134. local eventTime = time()
  135. local connection
  136. connection = Camera.Changed:connect(function()
  137. connection:disconnect()
  138. if eventTime == time() and Camera.Focus ~= focus then
  139. local camera_distance = PyramidCharacter.camera_distance
  140. Camera.Focus = Camera.CoordinateFrame * CFrame.new(0, 0, -camera_distance)
  141. PyramidCharacter.camera_position = (Camera.CoordinateFrame * CFrame.new(0, 0, -camera_distance)).p
  142. end
  143. end)
  144. coroutine.yield()
  145. if Camera.Focus == focus then
  146. PyramidCharacter.camera_distance = (focus.p - cframe.p).magnitude
  147. else
  148. local camera_distance = PyramidCharacter.camera_distance
  149. Camera.Focus = Camera.CoordinateFrame * CFrame.new(0, 0, -camera_distance)
  150. PyramidCharacter.camera_position = (Camera.CoordinateFrame * CFrame.new(0, 0, -camera_distance)).p
  151. end
  152. if connection.connected then
  153. connection:disconnect()
  154. end
  155. end
  156. end
  157. end)
  158. function PyramidCharacter.Animate()
  159. local total_time = time()
  160. local core = PyramidCharacter.core
  161. local frame = PyramidCharacter.frame
  162. if PyramidCharacter.visible then
  163. local core_mesh = PyramidCharacter.core_mesh
  164. local core_lights = PyramidCharacter.core_lights
  165. if not frame or frame.Parent ~= core then
  166. frame = Instance.new("Model")
  167. frame.Archivable = false
  168. frame.Parent = core
  169. PyramidCharacter.frame = frame
  170. end
  171. if core.Parent ~= Workspace then
  172. core = PyramidCharacter.stock_core:Clone()
  173. PyramidCharacter.core = core
  174. core.Archivable = false
  175. core.Parent = Workspace
  176. chatAdornee = core
  177. end
  178. if core_mesh.Parent ~= core then
  179. core_mesh = Instance.new("BlockMesh", core)
  180. PyramidCharacter.core_mesh = core_mesh
  181. end
  182. for index, core_light in ipairs(core_lights) do
  183. if core_light.Parent ~= core then
  184. core_light = Instance.new("PointLight", core)
  185. core_lights[index] = core_light
  186. end
  187. local vertexColor = Vector3.new(Utility.GetRainbowRGB(total_time)) * 0.25 + Vector3.new(1, 1, 1) * 0.75
  188. core_light.Color = Color3.new(vertexColor.X, vertexColor.Y, vertexColor.Z)
  189. core_light.Brightness = 0.85 + 0.15 * math.random()
  190. if core_light.Range ~= 30 then
  191. core_light.Range = 30
  192. end
  193. if not core_light.Shadows then
  194. core_light.Shadows = true
  195. end
  196. end
  197. if core_mesh.Offset ~= Vector3.new(0, 0, 0) then
  198. core_mesh.Offset = Vector3.new(0, 0, 0)
  199. end
  200. if not core.Anchored then
  201. core.Anchored = true
  202. end
  203. if core.Transparency ~= 0 then
  204. core.Transparency = 0
  205. end
  206. local core_mesh_scale = PyramidCharacter.core_mesh_scale
  207. local transition_speed = (math.sin(total_time * math.tau) + 1) / 16
  208. core_mesh_scale = core_mesh_scale * (1 - transition_speed) + Vector3.new(math.random() * 0.5 + 0.5, math.random() * 0.5 + 0.5, math.random()
  209.  
  210. * 0.5 + 0.5) * transition_speed
  211. core_mesh.Scale = core_mesh_scale * 2
  212. local center = CFrame.new(PyramidCharacter.camera_position) * CFrame.Angles(0, total_time * math.tau, 0)
  213. local cframe1 = CFrame.new(PyramidCharacter.head_radius, 0, 0)
  214. local cframe2 = CFrame.Angles(math.tau / -3, 0, 0)
  215. local cframe3 = CFrame.Angles(0, math.tau / 3, 0)
  216. local cframe4 = center * cframe3
  217. local desired1 = center * CFrame.new(0, PyramidCharacter.head_radius, 0)
  218. local desired2 = center * cframe2 * cframe1
  219. local desired3 = cframe4 * cframe2 * cframe1
  220. local desired4 = cframe4 * cframe3 * cframe2 * cframe1
  221. local point1 = (PyramidCharacter.point1 * 3 + desired1.p) / 4
  222. local point2 = (PyramidCharacter.point2 * 3 + desired2.p) / 4
  223. local point3 = (PyramidCharacter.point3 * 3 + desired3.p) / 4
  224. local point4 = (PyramidCharacter.point4 * 3 + desired4.p) / 4
  225. PyramidCharacter.point1 = point1
  226. PyramidCharacter.point2 = point2
  227. PyramidCharacter.point3 = point3
  228. PyramidCharacter.point4 = point4
  229. local head_properties = PyramidCharacter.head_properties
  230. PyramidCharacter.CreateTriangle(point1, point2, point3, head_properties, frame, 1).Archivable = false
  231. PyramidCharacter.CreateTriangle(point2, point3, point4, head_properties, frame, 2).Archivable = false
  232. PyramidCharacter.CreateTriangle(point3, point4, point1, head_properties, frame, 3).Archivable = false
  233. PyramidCharacter.CreateTriangle(point4, point1, point2, head_properties, frame, 4).Archivable = false
  234. core.CFrame = CFrame.new((point1 + point2 + point3 + point4) / 4) * CFrame.Angles(total_time * math.tau, total_time * math.tau / 2,
  235.  
  236. total_time * math.tau / 3)
  237. PyramidCharacter.center = center
  238. else
  239. if core.Parent then
  240. core:Destroy()
  241. end
  242. if frame and frame.Parent then
  243. frame:Destroy()
  244. end
  245. PyramidCharacter.frame = nil
  246. end
  247. end
  248. function PyramidCharacter.MainLoop()
  249. PyramidCharacter.Animate()
  250. RunService.Stepped:wait()
  251. end
  252. TaskScheduler.Start(function()
  253. while true do
  254. PyramidCharacter.MainLoop()
  255. end
  256. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement