Inertia script teleporting camera

I’ve got an Inertia script and any time I look up or down max it spins the camera pretty rapidly, I’m really not sure how I would even fix this.

local sensitivity = 0.1
local deceleration = 15

local cam = workspace.Camera

local rotate = Vector3.zero
local max = math.max
local rad = math.pi/180

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

game:GetService'RunService':BindToRenderStep('InertialCamera',Enum.RenderPriority.Camera.Value-1,function(dt)
	rotate *= 1-dt*deceleration
	cam.CFrame *= CFrame.fromOrientation(rotate.Y*rad,rotate.X*rad,0)
end)

You could try clamping the rotation with math.clamp

I tried that and it didn’t work, though I’m not sure if I did it correctly

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)
	rotate = rotate * (1 - dt * deceleration)

	local clampedX = math.clamp(rotate.X, maxLookDownAngle, maxLookUpAngle)
	rotate = Vector3.new(clampedX, rotate.Y, 0)

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

What happens if you do

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

	cam.CFrame = cam.CFrame * CFrame.fromOrientation(rotate.Y * rad, rotate.X * rad, 0)
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(newY * rad, rotate.X * rad, 0)
end)

my camera is just spinning now

lol

1 Like

btw you wrote newY in the formula, I’m not sure which you wanted but neither rotate.Y or clampedY worked.

problem still unsolved, haven’t been able to fix it.