Here’s the other method that doesn’t take roll into account when moving the mouse:
local Camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local position = Vector3.zero :: Vector3
local yaw = 0 :: number
local pitch = 0 :: number
local roll = 0 :: number
local sensitivity = 0.25 :: number
RunService.RenderStepped:Connect(function ()
local delta = UserInputService:GetMouseDelta()
pitch = (pitch + delta.Y * sensitivity) % 360
yaw = (yaw + delta.X * sensitivity) % 360
local yawRad = math.rad(yaw)
local pitchRad = math.rad(pitch)
local yawQuat = CFrame.new(position.X, position.Y, position.Z, 0, math.sin(math.rad(yaw) * 0.5), 0, math.cos(math.rad(yaw) * 0.5))
local pitchQuat = CFrame.new(position.X, position.Y, position.Z, math.sin(math.rad(pitch) * 0.5), 0, 0, math.cos(math.rad(pitch) * 0.5))
local rollQuat = CFrame.new(position.X, position.Y, position.Z, 0, 0, math.sin(math.rad(roll) * 0.5), math.cos(math.rad(roll) * 0.5))
local orientation = yawQuat * pitchQuat * rollQuat
Camera.CFrame = CFrame.fromMatrix(position, orientation.RightVector, orientation.UpVector, -orientation.LookVector)
end)
You can omit roll entirely if you aren’t going to use it
Without roll
local Camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local position = Vector3.zero :: Vector3
local yaw = 0 :: number
local pitch = 0 :: number
local sensitivity = 0.25 :: number
RunService.RenderStepped:Connect(function ()
local delta = UserInputService:GetMouseDelta()
pitch = (pitch + delta.Y * sensitivity) % 360
yaw = (yaw + delta.X * sensitivity) % 360
local yawRad = math.rad(yaw)
local pitchRad = math.rad(pitch)
local yawQuat = CFrame.new(position.X, position.Y, position.Z, 0, math.sin(math.rad(yaw) * 0.5), 0, math.cos(math.rad(yaw) * 0.5))
local pitchQuat = CFrame.new(position.X, position.Y, position.Z, math.sin(math.rad(pitch) * 0.5), 0, 0, math.cos(math.rad(pitch) * 0.5))
local orientation = yawQuat * pitchQuat
Camera.CFrame = CFrame.fromMatrix(position, orientation.RightVector, orientation.UpVector, -orientation.LookVector)
end)