Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local camera = workspace.CurrentCamera
- local humanoid = script.Parent:WaitForChild("Humanoid")
- local start = tick()
- function shakeCamera(initialTrauma, shakeCentre, blur)
- --initialTrauma (necessary, number) = intensity of camera shake
- --shakeCentre (optional, vector3) = position of shake; distance between shake and camera reduces intensity if shakeCentre is given
- --blur (optional, bool) = create blur effect with camera shake
- local iterator = 0
- local seed = Random.new():NextNumber()
- local blurEffect = nil
- if blur == true then
- blurEffect = Instance.new("BlurEffect")
- blurEffect.Size = 0
- blurEffect.Parent = game.Lighting
- end
- while initialTrauma > 0 do
- game:GetService("RunService").Heartbeat:Wait()
- local now = tick() - start
- iterator += 1
- local shake = (initialTrauma ^ 2)
- if shakeCentre then
- local distance = (camera.CFrame.Position - shakeCentre).Magnitude
- shake = shake / math.clamp((distance * 0.1), 0.7, math.huge)
- end
- local noiseX = (math.noise(iterator, now, seed)) * shake
- local noiseY = (math.noise(iterator + 1, now, seed)) * shake
- local noiseZ = (math.noise(iterator + 2 + 1, now, seed)) * shake
- humanoid.CameraOffset = Vector3.new(noiseX, noiseY, noiseZ)
- camera.CFrame = camera.CFrame * CFrame.Angles(noiseX / 50, noiseY / 50, noiseZ / 50)
- if blurEffect then
- blurEffect.Size = shake * 12
- end
- local falloffSpeed = 1.6
- initialTrauma = math.clamp(initialTrauma - falloffSpeed * game:GetService("RunService").Heartbeat:Wait(), 0, 1)
- end
- humanoid.CameraOffset = Vector3.new(0, 0, 0)
- if blurEffect then
- blurEffect:Destroy()
- end
- end
- --example of use:
- shakeCamera(1, script.Parent.HumanoidRootPart.Position, true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement