So the issue is that camera doesnt move with the player and you cant move the camera with your mouse. Ive never done camera stuff before (except really simple stuff)
External Medialocal CameraService = {}
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable
local function EaseInSine(x)
return 1 - math.cos((x * math.pi)/2)
end
local function EaseInQuad(x)
return x * x
end
local function EaseInCubic(x)
return x * x * x
end
local function MakeEasing(inFunc)
return {
In = inFunc,
Out = function(x) return 1 - inFunc(1 - x) end,
InOut = function(x)
return x < 0.5 and inFunc(x*2)/2 or 1 - inFunc((1 - x)*2)/2
end
}
end
local EASING = {
Sine = MakeEasing(EaseInSine),
Quad = MakeEasing(EaseInQuad),
Cubic = MakeEasing(EaseInCubic),
Linear = {
In = function(x) return x end,
Out = function(x) return x end,
InOut = function(x) return x end
}
}
local ActiveEffects = {}
function CameraService:AddEffect(func)
table.insert(ActiveEffects, func)
return func -- token for removal
end
function CameraService:RemoveEffect(token)
for i, v in ipairs(ActiveEffects) do
if v == token then
table.remove(ActiveEffects, i)
break
end
end
end
function CameraService:AddRotationOffsetTemp(pitch, yaw, time, easingStyle, easingDirection)
local half = time / 2
local t = 0
local style = EASING[easingStyle.Name] or EASING.Linear
local ease = style[easingDirection and easingDirection.Name or "InOut"] or style.InOut
local token
token = self:AddEffect(function()
if t >= time then
CameraService:RemoveEffect(token)
return CFrame.new() -- reset to the default state once finished
end
local dt = RunService.RenderStepped:Wait()
t += dt
local alpha = (t <= half) and (t / half) or (1 - ((t - half)/half))
alpha = ease(math.clamp(alpha, 0, 1))
-- make sure both directions are covered smoothly
return CFrame.Angles(
math.rad(pitch) * alpha,
math.rad(yaw) * alpha,
0
)
end)
return token
end
function CameraService:Shake(power, time)
local t = 0
local token
token = self:AddEffect(function()
if t >= time then
CameraService:RemoveEffect(token)
return CFrame.new()
end
t += RunService.RenderStepped:Wait()
local x = (math.random() - 0.5) * power
local y = (math.random() - 0.5) * power
return CFrame.Angles(math.rad(x), math.rad(y), 0)
end)
return token
end
function CameraService:Recoil(upAngle, recoveryTime)
local angle = upAngle
local token
token = self:AddEffect(function()
if angle <= 0 then
CameraService:RemoveEffect(token)
return CFrame.new()
end
local dt = RunService.RenderStepped:Wait()
angle -= (upAngle / recoveryTime) * dt
return CFrame.Angles(math.rad(angle), 0, 0)
end)
return token
end
RunService.RenderStepped:Connect(function()
local base = cam.CFrame
local offset = CFrame.new()
for _, effectFunc in ipairs(ActiveEffects) do
offset = offset * effectFunc()
end
cam.CFrame = base * offset
end)
return CameraService