Camera Inertia/Glide spinning my camera

I’m trying to make an Inertia/Camera glide script, but I was having a problem where if I moved my camera all the way up or down quickly it would spin me around, I tried to fix it and now my camera is just spinning always.

local sensitivity = 0.1
local deceleration = 15

local cam = workspace.CurrentCamera

local rotate = Vector3.new(0, 0, 0)
local rad = math.pi / 180

local maxLookUpAngle = 50
local maxLookDownAngle = -50

local mouseMove = Enum.UserInputType.MouseMovement
game:GetService('UserInputService').InputChanged:Connect(function(input)
	if input.UserInputType == mouseMove then
		rotate = rotate - input.Delta * sensitivity
	end
end)

game:GetService("RunService"):BindToRenderStep("InertialCamera", Enum.RenderPriority.Camera.Value - 1, function(dt)
	local originalY = rotate.Y
	rotate = rotate * (1 - dt * deceleration)
	
	local clampedY = math.clamp(originalY + rotate.Y, maxLookDownAngle, maxLookUpAngle)
	rotate = Vector3.new(rotate.X, clampedY, 0)

	cam.CFrame = cam.CFrame * CFrame.fromOrientation(rotate.Y * rad, rotate.X * rad, 0)
end)
1 Like

The issue is that you are clamping the angular velocity instead of the final angles.

1 Like

Thanks very much, this helped a ton.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.