Camera shake script help

hello can someone help me with this script:

local runService = game:GetService("RunService")

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

function updateBobbleEffect()
	local currentTime = tick()
	if humanoid.MoveDirection.Magnitude > 0 then -- we are walking
		local bobbleY = math.abs(math.sin(currentTime * 10)) * .35
		local bobbleX = math.abs(math.sin(currentTime * 10)) * .05

		local bobble = Vector3.new(bobbleX, bobbleY, 0)

		humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, .2)
	else -- we are not walking
		humanoid.CameraOffset = Vector3.new(0, 0, -1)
	end
end

runService.RenderStepped:Connect(updateBobbleEffect)

it’s a shaking script, the problem is if the player walks the camera swing back I don’t know what the problem is

1 Like

I am not a professional lua programmer.
But you could try moving the camera forward like you have done, while the Character isn’t running.

Or you could try using this:
local bobble = Vector3.new(bobbleX, bobbleY, -1)

As I said I am not a professional programmer, so I am guessing.

2 Likes