Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local module = {}
- local active = {}
- local connections = {}
- local runs = game:GetService("RunService")
- local plr = game.Players.LocalPlayer
- local hum = plr.Character and plr.Character:FindFirstChildOfClass("Humanoid")
- local function calc(t, i)
- local seed = math.random(1, 100000)
- local noise = 0.7
- local x = (math.noise(seed, t, 0) * noise + math.random(-1, 1) * (1 - noise))
- local y = (math.noise(seed + 1, t, 0) * noise + math.random(-1, 1) * (1 - noise))
- local z = (math.noise(seed + 2, t, 0) * noise + math.random(-1, 1) * (1 - noise))
- return Vector3.new(x, y, z) * i
- end
- local function dist(cam, part)
- local dist = (part.Position - cam.CFrame.Position).Magnitude
- local max = 75
- local min = 5
- return math.clamp(1 - (dist - min)/(max - min), 0, 1)
- end
- local function update(dt)
- local cam = workspace.CurrentCamera
- if not cam then return end
- if not next(active) then
- if hum then
- hum.CameraOffset = Vector3.zero
- end
- if connections.render then
- connections.render:Disconnect()
- connections.render = nil
- end
- return
- end
- local tot = Vector3.zero
- for part, data in pairs(active) do
- if part and part.Parent then
- data.e = (data.e or 0) + dt
- if data.d and data.e >= data.d then
- active[part] = nil
- else
- local factor = dist(cam, part)
- if factor > 0 then
- local i = data.i * factor
- local offset = calc(data.e, i)
- tot += offset
- end
- end
- else
- active[part] = nil
- end
- end
- if hum then
- hum.CameraOffset = tot
- end
- end
- function module.start(part, d, i)
- if not part or not part:IsA("BasePart") then
- warn("Shake target must be a BasePart")
- return
- end
- active[part] = {
- i = i ~= nil and math.clamp(i, 0.025, 10) or 0.75,
- d = d ~= nil and d or math.huge,
- e = 0
- }
- if not connections.render then
- connections.render = runs.RenderStepped:Connect(update)
- end
- end
- function module.modify(part, i)
- if active[part] then
- if i then active[part].i = math.clamp(i, 0.025, 10) end
- end
- end
- function module.stop(part)
- active[part] = nil
- end
- local function cleanup()
- table.clear(active)
- if connections.render then
- connections.render:Disconnect()
- connections.render = nil
- end
- end
- plr.CharacterRemoving:Connect(cleanup)
- return module
Advertisement
Add Comment
Please, Sign In to add comment