Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PyramidCharacter = {};
- local stock_triangle = Instance.new("WedgePart")
- stock_triangle.Anchored = true
- stock_triangle.BottomSurface = "Smooth"
- stock_triangle.FormFactor = "Custom"
- stock_triangle.Locked = true
- stock_triangle.TopSurface = "Smooth"
- local stock_triangle_mesh = Instance.new("SpecialMesh", stock_triangle)
- stock_triangle_mesh.MeshType = "Wedge"
- local triangles = {}
- function PyramidCharacter.CreateTriangle(v1, v2, v3, properties, parent, index)
- local triangleInfo = triangles[index]
- local side1 = (v1 - v2).magnitude
- local side2 = (v2 - v3).magnitude
- local side3 = (v3 - v1).magnitude
- local sqrside1 = side1 * side1
- local sqrside2 = side2 * side2
- local sqrside3 = side3 * side3
- if sqrside3 + sqrside1 == sqrside2 then
- v1, v2, v3 = v1, v2, v3
- elseif sqrside1 + sqrside2 == sqrside3 then
- v1, v2, v3 = v2, v3, v1
- elseif sqrside2 + sqrside3 == sqrside1 then
- v1, v2, v3 = v3, v1, v2
- elseif sqrside1 >= sqrside2 and sqrside1 >= sqrside3 then
- v1, v2, v3 = v1, v2, v3
- elseif sqrside2 >= sqrside3 and sqrside2 >= sqrside1 then
- v1, v2, v3 = v2, v3, v1
- else
- v1, v2, v3 = v3, v1, v2
- end
- local model, part1, part2, mesh1, mesh2
- if triangleInfo then
- model, part1, part2, mesh1, mesh2 = unpack(triangleInfo)
- if not (model.Parent == parent and part1.Parent == model and part2.Parent == model and mesh1.Parent == part1 and mesh2.Parent == part2) then
- if model.Parent then
- model:Destroy()
- end
- model = nil
- end
- else
- triangleInfo = {}
- triangles[index] = triangleInfo
- end
- if not model then
- model = Instance.new("Model")
- part1 = stock_triangle:Clone()
- part2 = stock_triangle:Clone()
- mesh1 = part1.Mesh
- mesh2 = part2.Mesh
- part1.Parent = model
- part2.Parent = model
- triangleInfo[1] = model
- triangleInfo[2] = part1
- triangleInfo[3] = part2
- triangleInfo[4] = mesh1
- triangleInfo[5] = mesh2
- end
- for key, value in pairs(properties) do
- part1[key] = value
- part2[key] = value
- end
- local cframe = CFrame.new(v1, v2)
- local relpos = cframe:pointToObjectSpace(v3)
- cframe = cframe * CFrame.fromEulerAnglesXYZ(0, 0, -math.atan2(relpos.x, relpos.y))
- local rel1 = cframe:pointToObjectSpace(v1)
- local rel2 = cframe:pointToObjectSpace(v2)
- local rel3 = cframe:pointToObjectSpace(v3)
- local height = rel3.y
- local width1 = rel3.z
- local width2 = rel2.z - rel3.z
- local relcenter1 = Vector3.new(0, height / 2, width1 / 2)
- local center1 = cframe:pointToWorldSpace(relcenter1)
- local relcenter2 = Vector3.new(0, height / 2, width2 / 2 + width1)
- local center2 = cframe:pointToWorldSpace(relcenter2)
- height = math.abs(height)
- width1 = math.abs(width1)
- width2 = math.abs(width2)
- if not part1.Anchored then
- part1.Anchored = true
- end
- part1.Size = Vector3.new(0.2, height, width1)
- part1.CFrame = cframe * CFrame.fromEulerAnglesXYZ(0, math.pi, 0) - cframe.p + center1
- mesh1.Scale = Vector3.new(0, height / part1.Size.y, width1 / part1.Size.z)
- if not part2.Anchored then
- part2.Anchored = true
- end
- part2.Size = Vector3.new(0.2, height, width1)
- part2.CFrame = cframe - cframe.p + center2
- mesh2.Scale = Vector3.new(0, height / part1.Size.y, width2 / part2.Size.z)
- model.Parent = parent
- return model
- end
- PyramidCharacter.head_properties = {BrickColor = BrickColor.new(Color3.new(1, 1, 1)), Transparency = 0.5}
- PyramidCharacter.head_radius = math.pi
- PyramidCharacter.center = CFrame.new(0, 10, 0)
- PyramidCharacter.point1 = Vector3.new()
- PyramidCharacter.point2 = Vector3.new()
- PyramidCharacter.point3 = Vector3.new()
- PyramidCharacter.point4 = Vector3.new()
- PyramidCharacter.core_mesh_scale = Vector3.new(0.833, 0.833, 0.833)
- PyramidCharacter.visible = false
- function PyramidCharacter.Teleport(location)
- PyramidCharacter.point1 = location
- PyramidCharacter.point2 = location
- PyramidCharacter.point3 = location
- PyramidCharacter.point4 = location
- end
- local stock_core = Instance.new("Part")
- stock_core.Anchored = true
- stock_core.BottomSurface = "Smooth"
- stock_core.Color = Color3.new(1, 1, 1)
- stock_core.FormFactor = "Custom"
- stock_core.Locked = true
- stock_core.Name = "CubePyramid"
- stock_core.Size = Vector3.new(0.5, 0.5, 0.5)
- stock_core.TopSurface = "Smooth"
- PyramidCharacter.stock_core = stock_core
- PyramidCharacter.core = stock_core:Clone()
- PyramidCharacter.Archivable = false
- PyramidCharacter.core_mesh = Instance.new("BlockMesh", core)
- PyramidCharacter.core_lights = {}
- PyramidCharacter.coreLightCount = 1
- for index = 1, PyramidCharacter.coreLightCount do
- PyramidCharacter.core_lights[index] = Instance.new("PointLight", core)
- end
- PyramidCharacter.camera_distance = (Camera.Focus.p - Camera.CoordinateFrame.p).magnitude
- PyramidCharacter.camera_position = Vector3.new()
- Camera.Changed:connect(function(property)
- if PyramidCharacter.visible then
- if property == "CoordinateFrame" then
- local cframe, focus = Camera.CoordinateFrame, Camera.Focus
- local eventTime = time()
- local connection
- connection = Camera.Changed:connect(function()
- connection:disconnect()
- if eventTime == time() and Camera.Focus ~= focus then
- local camera_distance = PyramidCharacter.camera_distance
- Camera.Focus = Camera.CoordinateFrame * CFrame.new(0, 0, -camera_distance)
- PyramidCharacter.camera_position = (Camera.CoordinateFrame * CFrame.new(0, 0, -camera_distance)).p
- end
- end)
- coroutine.yield()
- if Camera.Focus == focus then
- PyramidCharacter.camera_distance = (focus.p - cframe.p).magnitude
- else
- local camera_distance = PyramidCharacter.camera_distance
- Camera.Focus = Camera.CoordinateFrame * CFrame.new(0, 0, -camera_distance)
- PyramidCharacter.camera_position = (Camera.CoordinateFrame * CFrame.new(0, 0, -camera_distance)).p
- end
- if connection.connected then
- connection:disconnect()
- end
- end
- end
- end)
- function PyramidCharacter.Animate()
- local total_time = time()
- local core = PyramidCharacter.core
- local frame = PyramidCharacter.frame
- if PyramidCharacter.visible then
- local core_mesh = PyramidCharacter.core_mesh
- local core_lights = PyramidCharacter.core_lights
- if not frame or frame.Parent ~= core then
- frame = Instance.new("Model")
- frame.Archivable = false
- frame.Parent = core
- PyramidCharacter.frame = frame
- end
- if core.Parent ~= Workspace then
- core = PyramidCharacter.stock_core:Clone()
- PyramidCharacter.core = core
- core.Archivable = false
- core.Parent = Workspace
- chatAdornee = core
- end
- if core_mesh.Parent ~= core then
- core_mesh = Instance.new("BlockMesh", core)
- PyramidCharacter.core_mesh = core_mesh
- end
- for index, core_light in ipairs(core_lights) do
- if core_light.Parent ~= core then
- core_light = Instance.new("PointLight", core)
- core_lights[index] = core_light
- end
- local vertexColor = Vector3.new(Utility.GetRainbowRGB(total_time)) * 0.25 + Vector3.new(1, 1, 1) * 0.75
- core_light.Color = Color3.new(vertexColor.X, vertexColor.Y, vertexColor.Z)
- core_light.Brightness = 0.85 + 0.15 * math.random()
- if core_light.Range ~= 30 then
- core_light.Range = 30
- end
- if not core_light.Shadows then
- core_light.Shadows = true
- end
- end
- if core_mesh.Offset ~= Vector3.new(0, 0, 0) then
- core_mesh.Offset = Vector3.new(0, 0, 0)
- end
- if not core.Anchored then
- core.Anchored = true
- end
- if core.Transparency ~= 0 then
- core.Transparency = 0
- end
- local core_mesh_scale = PyramidCharacter.core_mesh_scale
- local transition_speed = (math.sin(total_time * math.tau) + 1) / 16
- 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()
- * 0.5 + 0.5) * transition_speed
- core_mesh.Scale = core_mesh_scale * 2
- local center = CFrame.new(PyramidCharacter.camera_position) * CFrame.Angles(0, total_time * math.tau, 0)
- local cframe1 = CFrame.new(PyramidCharacter.head_radius, 0, 0)
- local cframe2 = CFrame.Angles(math.tau / -3, 0, 0)
- local cframe3 = CFrame.Angles(0, math.tau / 3, 0)
- local cframe4 = center * cframe3
- local desired1 = center * CFrame.new(0, PyramidCharacter.head_radius, 0)
- local desired2 = center * cframe2 * cframe1
- local desired3 = cframe4 * cframe2 * cframe1
- local desired4 = cframe4 * cframe3 * cframe2 * cframe1
- local point1 = (PyramidCharacter.point1 * 3 + desired1.p) / 4
- local point2 = (PyramidCharacter.point2 * 3 + desired2.p) / 4
- local point3 = (PyramidCharacter.point3 * 3 + desired3.p) / 4
- local point4 = (PyramidCharacter.point4 * 3 + desired4.p) / 4
- PyramidCharacter.point1 = point1
- PyramidCharacter.point2 = point2
- PyramidCharacter.point3 = point3
- PyramidCharacter.point4 = point4
- local head_properties = PyramidCharacter.head_properties
- PyramidCharacter.CreateTriangle(point1, point2, point3, head_properties, frame, 1).Archivable = false
- PyramidCharacter.CreateTriangle(point2, point3, point4, head_properties, frame, 2).Archivable = false
- PyramidCharacter.CreateTriangle(point3, point4, point1, head_properties, frame, 3).Archivable = false
- PyramidCharacter.CreateTriangle(point4, point1, point2, head_properties, frame, 4).Archivable = false
- core.CFrame = CFrame.new((point1 + point2 + point3 + point4) / 4) * CFrame.Angles(total_time * math.tau, total_time * math.tau / 2,
- total_time * math.tau / 3)
- PyramidCharacter.center = center
- else
- if core.Parent then
- core:Destroy()
- end
- if frame and frame.Parent then
- frame:Destroy()
- end
- PyramidCharacter.frame = nil
- end
- end
- function PyramidCharacter.MainLoop()
- PyramidCharacter.Animate()
- RunService.Stepped:wait()
- end
- TaskScheduler.Start(function()
- while true do
- PyramidCharacter.MainLoop()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement