Snappy camera bob

Hello.
I seem to have a little problem with this script I have. it’s a camera bob script, but it feels kinda wonky. Everytime I let go of the W key, it just snaps.

VIDEO:

Here is the code:

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 bobbleX = math.cos(currentTime * 4) * .35
		local bobbleY = math.abs(math.sin(currentTime * 4)) * .35

		local bobble = Vector3.new(bobbleX, bobbleY, -0.45)

		humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, .25)
	else -- we are not walking
		humanoid.CameraOffset = Vector3.new(0, 0, -0.5)
		humanoid.CameraOffset = humanoid.CameraOffset * .75
	end
end

runService.RenderStepped:Connect(updateBobbleEffect)

What could I do to fix it?

2 Likes

Try tweening the camera in your else statement instead of snapping to that CFrame.

1 Like

how would I do that? do I add a statement like

ts:Create(humanoid, tweeninf, {cameraoffset = vector3.new(0,0,-0.5)}):Play()

This is just an example

It actually worked lol, THank you Scottifly!

1 Like