Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- SETTINGS
- local numParts = 8 -- number of parts
- local partDepth = 4 -- initial Z size
- local partHeight = 1
- local travelDistance = 50 -- studs to move forward
- local animationTime = 3 -- seconds to complete movement
- local lightRange = 20
- local lightBrightness = 2
- -- SETUP
- local model = script.Parent
- for _, obj in ipairs(model:GetChildren()) do
- if obj:IsA("BasePart") then
- obj:Destroy()
- end
- end
- local parts = {}
- for i = 0, numParts - 1 do
- local angle = i * (2 * math.pi / numParts)
- local part = Instance.new("Part")
- part.Anchored = true
- part.CanCollide = false
- part.Size = Vector3.new(0, partHeight, partDepth) -- width will change
- part.CFrame = CFrame.new(0, 0, 0) * CFrame.Angles(0, -angle, 0)
- part.Parent = model
- local light = Instance.new("SurfaceLight")
- light.Face = Enum.NormalId.Front
- light.Angle = 360 / numParts
- light.Range = lightRange
- light.Brightness = lightBrightness
- light.Parent = part
- table.insert(parts, {
- part = part,
- angle = angle
- })
- end
- -- ANIMATION
- local runService = game:GetService("RunService")
- local startTime = tick()
- local connection
- connection = runService.Heartbeat:Connect(function()
- local elapsed = tick() - startTime
- local alpha = math.min(elapsed / animationTime, 1)
- local r = alpha * travelDistance
- for _, data in ipairs(parts) do
- -- Calculate width so edges touch
- local width = 2 * r * math.sin(math.pi / numParts)
- if width < 0.05 then width = 0.05 end -- prevent zero size
- -- Update size
- data.part.Size = Vector3.new(width, partHeight, partDepth)
- -- Position outward along local Z axis
- local pos = CFrame.new(0, 0, r) -- move along local Z
- data.part.CFrame = CFrame.Angles(0, -data.angle, 0) * pos * CFrame.Angles(0, -data.angle, 0)
- end
- if alpha >= 1 then
- connection:Disconnect()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment