--< Services >--
local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
--< Constants >--
local SENSITIVITY = Vector2.new(1 / 250, 1 / 250)
local MIN_Y, MAX_Y = math.rad(-80), math.rad(80)
--< Variables >--
local Player = Players.LocalPlayer
local Camera = Workspace.CurrentCamera
local AngleX, AngleY = 0, 0
--< Functions >--
local function OnInputChanged(input, processed)
if processed then return end
AngleX = (AngleX - input.Delta.X * SENSITIVITY.X) % (math.pi * 2)
AngleY = math.clamp(AngleY - input.Delta.Y * SENSITIVITY.Y, MIN_Y, MAX_Y)
end
local function Update(dt)
local Character = Player.Character
if Character then
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart then
local Attachment = HumanoidRootPart:FindFirstChild("CameraAttachment")
if Attachment then
HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position) * CFrame.Angles(0, math.rad(AngleX), 0)
Camera.CFrame = CFrame.new(Attachment.WorldPosition) * CFrame.Angles(0, AngleX, 0) * CFrame.Angles(AngleY, 0, 0)
end
end
end
end
--< Initialize >--
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
--< Connections >--
UserInputService.InputChanged:Connect(OnInputChanged)
RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, Update)
I am running into a weird issue where the camera drifts upwards only when the mouse is locked to the center. I will be moving my mouse only horizontally yet input.Delta.Y
not close to 0. I don’t know what could be causing this.
EDIT: Turns out this only happens in studio.