this is a script that makes the camera bounce.
i use it in a lot of my projects and it works perfectly fine
local CurrentSpread = 20
local CurrentRecoil = 1.3
local Stance = 0
local StanceSway = 1
local CameraSway = 1
local ABS, HUGE, FLOOR, CEIL = math.abs, math.huge, math.floor, math.ceil
local RAD, SIN, ATAN, COS = math.rad, math.sin, math.atan2, math.cos
local VEC3 = Vector3.new
local CF, CFANG = CFrame.new, CFrame.Angles
local INSERT = table.insert
local Camera = game.Workspace.CurrentCamera
function RAND(Min, Max, Accuracy)
local Inverse = 1 / (Accuracy or 1)
return (math.random(Min * Inverse, Max * Inverse) / Inverse)
end
local RecoilX = RAD(CurrentRecoil * RAND(1, 1.5, 0.1)) * StanceSway
local RecoilY = RAD(CurrentRecoil * RAND(-2, 2, 0.1)) * StanceSway
local RS = game:GetService("RunService").RenderStepped
local Selected = true
function RotCamera(RotX, RotY, SmoothRot, Duration)
spawn(function()
if SmoothRot then
local TweenIndicator = nil
local NewCode = math.random(-1e9, 1e9)
if (not Camera:FindFirstChild("TweenCode")) then
TweenIndicator = Instance.new("IntValue")
TweenIndicator.Name = "TweenCode"
TweenIndicator.Value = NewCode
TweenIndicator.Parent = Camera
else
TweenIndicator = Camera.TweenCode
TweenIndicator.Value = NewCode
end
local Step = math.min(1.5 / math.max(Duration, 0), 90)
local X = 0
while true do
local NewX = X + Step
X = (NewX > 90 and 90 or NewX)
if TweenIndicator.Value ~= NewCode then break end
if (not Selected) then break end
local CamRot = Camera.CoordinateFrame - Camera.CoordinateFrame.p
local CamDist = (Camera.CoordinateFrame.p - Camera.Focus.p).magnitude
local NewCamCF = CF(Camera.Focus.p) * CamRot * CFANG(RotX / (90 / Step), RotY / (90 / Step), 0)
Camera.CoordinateFrame = CF(NewCamCF.p, NewCamCF.p + NewCamCF.lookVector) * CF(0, 0, CamDist)
if X == 90 then break end
RS:wait()
end
if TweenIndicator.Value == NewCode then
TweenIndicator:Destroy()
end
else
local CamRot = Camera.CoordinateFrame - Camera.CoordinateFrame.p
local CamDist = (Camera.CoordinateFrame.p - Camera.Focus.p).magnitude
local NewCamCF = CF(Camera.Focus.p) * CamRot * CFANG(RotX, RotY, 0)
Camera.CoordinateFrame = CF(NewCamCF.p, NewCamCF.p + NewCamCF.lookVector) * CF(0, 0, CamDist)
end
end)
end
use this to bounce the camera:
RotCamera(RecoilX, RecoilY, true, 0.06)