Help fixing a Camera Bobbing Bug

  1. What do you want to achieve?
    I want for my head bobbing to bob the camera smoothly. The camera bobbing is basically bouncing on the Y axis.

  2. What is the issue?
    Since the bobbing is running on tick() which goes on forever and when walking is pretty noticeable when the camera hops high and doing the head bobbing cycle.

  3. What solutions have you tried so far?
    I tried seeing some videos and the Devforum but I couldn’t find what I want.

-- hum = the humanoid of the local player

local function bob()
	if hum.MoveDirection.Magnitude > 0 and hum.Sit == false then
		local currentTime = tick()
		local bobbleY = math.abs(math.sin(currentTime * 5)) * .5
		local bobble = Vector3.new(0, bobbleY, 0)
		
		hum.CameraOffset = hum.CameraOffset:lerp(bobble, 1)
	else
		hum.CameraOffset = hum.CameraOffset * .75
	end
end
1 Like

math.sin should go from -1 to 1 for every 3.14 of input. Since you’re multiplying by five and using abs, this number should go from 0 to 1 every 0.3 seconds by my math. Is that the issue? Does it help to multiply by 0.75 instead of 5?

No, thats just making the walk slower. Here’s what I ment: