How to make camera sway

  1. Trying to find how to make a players camera sway.

  2. I don’t know how to achieve this.

What kind of swaying are you looking for? Like an effect to sway the camera as you walk?

Always use the Search button up top.
I don’t know how to make this effect, but I typed in ‘camera sway’ and got a bunch of previously written and solved posts.

I don’t know what kind of swaying you’re looking for, so hopefully, this will help.

It involves a bit of math, but I’ll just assume a basic sway when you walk is what was wanted.

This would be a LocalScript inside of StarterPlayerStarterCharacterScripts:

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local sin = math.sin
local cos = math.cos
local abs = math.abs

local effectIntensity = 10
local xDampening = 0.5
local yDampening = 0.3

local function updateSway()
	if humanoid and humanoid.Health > 0 and humanoid.MoveDirection.Magnitude > 0 then
		local swayX = cos(tick() * effectIntensity) * xDampening
		local swayY = abs(sin(tick() * effectIntensity)) * yDampening
		
		humanoid.CameraOffset = humanoid.CameraOffset:lerp(Vector3.new(swayX, swayY, 0), 0.4)
	elseif humanoid and humanoid.Health > 0 then
		TweenService:Create(humanoid, TweenInfo.new(0.2), {
			CameraOffset = Vector3.new(0, 0, 0)
		}):Play()
	end 
end

RunService.Heartbeat:Connect(updateSway)
3 Likes