Advertisement
Team_Alex

Untitled

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