Weird Camera bug

When I move the character’s face of direction, from left or right, while looking at the side the camera moves either closer or further away during the switch up. I’m trying to get the camera to trail behind the player.


local trailAlpha = 0.1

game:GetService("RunService").RenderStepped:Connect(function(dt)
	local vel = rootPart.Velocity
	local walkspeed = char.Humanoid.WalkSpeed

	-- Horizontal velocity for forward camera lag
	local horizontalVel = Vector3.new(vel.X, 0, vel.Z)
	local speed = horizontalVel.Magnitude
	local forwardOffset = 3 * speed / (walkspeed * 2)

	-- Vertical velocity for jump/fall lag (positive when jumping, negative when falling)
	local verticalOffset = math.clamp(vel.Y / 30, -5, 5)  -- smooth and bounded

	-- Combine both into a final camera offset
	local targetOffset = Vector3.new(0, verticalOffset, forwardOffset)
	char.Humanoid.CameraOffset = char.Humanoid.CameraOffset:Lerp(targetOffset, trailAlpha)
end)

It trails perfectly fine. But when I switch up around, it causes that weird glitch. If you look at the very bottom studs you can see.

1 Like