function BaseCamera.GetMeasuredDistanceToFocus(l)local u=game.Workspace.CurrentCamera if u then return(u.CoordinateFrame.p-u.Focus.p).magnitude end return nil end function BaseCamera.GetCameraLookVector(l)return game.Workspace.CurrentCamera and game.Workspace.CurrentCamera.CFrame.lookVector or UNIT_Z end function BaseCamera.CalculateNewLookCFrameFromArg(V,l,u)local p=l or V:GetCameraLookVector()local n=math.asin(p.y)local h=math.clamp(u.y,-MAX_Y+n,-MIN_Y+n)local T=Vector2.new(u.x,h)local N=CFrame.new(ZERO_VECTOR3,p)local Y=(CFrame.Angles(0,-T.x,0)*N)*CFrame.Angles(-T.y,0,0)return Y end function BaseCamera.CalculateNewLookVectorFromArg(V,l,u)local p=V:CalculateNewLookCFrameFromArg(l,u)return p.lookVector end function BaseCamera.CalculateNewLookVectorVRFromArg(u,l)local V=u:GetSubjectPosition()local p=V-game.Workspace.CurrentCamera.CFrame.p local n=(p*X1_Y0_Z1).unit local h=Vector2.new(l.x,0)local T=CFrame.new(ZERO_VECTOR3,n)local N=((CFrame.Angles(0,-h.x,0)*T)*CFrame.Angles(-h.y,0,0)).lookVector return(N*X1_Y0_Z1).unit end function BaseCamera.GetHumanoid(l)local u=player and player.Character if u then local V=l.humanoidCache[player]if V and V.Parent==u then return V else l.humanoidCache[player]=nil local V=u:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")if V then l.humanoidCache[player]=V end return V end end return nil end function BaseCamera.GetHumanoidPartToFollow(V,l,u)if u==Enum.HumanoidStateType.Dead then local u=l.Parent if u then return u:FindFirstChild("\072\101\097\100")or l.Torso else return l.Torso end else return l.Torso end end
-- Actual measured distance to the camera Focus point, which may be needed in special circumstances, but should
-- never be used as the starting point for updating the nominal camera-to-subject distance (self.currentSubjectDistance)
-- since that is a desired target value set only by mouse wheel (or equivalent) input, PopperCam, and clamped to min max camera distance
function BaseCamera:GetMeasuredDistanceToFocus()
	local camera = game.Workspace.CurrentCamera
	if camera then
		return (camera.CoordinateFrame.p - camera.Focus.p).magnitude
	end
	return nil
end

function BaseCamera:GetCameraLookVector()
	return game.Workspace.CurrentCamera and game.Workspace.CurrentCamera.CFrame.lookVector or UNIT_Z
end

function BaseCamera:CalculateNewLookCFrameFromArg(suppliedLookVector, rotateInput)
	local currLookVector = suppliedLookVector or self:GetCameraLookVector()
	local currPitchAngle = math.asin(currLookVector.y)
	local yTheta = math.clamp(rotateInput.y, -MAX_Y + currPitchAngle, -MIN_Y + currPitchAngle)
	local constrainedRotateInput = Vector2.new(rotateInput.x, yTheta)
	local startCFrame = CFrame.new(ZERO_VECTOR3, currLookVector)
	local newLookCFrame = CFrame.Angles(0, -constrainedRotateInput.x, 0)
		* startCFrame
		* CFrame.Angles(-constrainedRotateInput.y, 0, 0)
	return newLookCFrame
end

function BaseCamera:CalculateNewLookVectorFromArg(suppliedLookVector, rotateInput)
	local newLookCFrame = self:CalculateNewLookCFrameFromArg(suppliedLookVector, rotateInput)
	return newLookCFrame.lookVector
end

function BaseCamera:CalculateNewLookVectorVRFromArg(rotateInput)
	local subjectPosition = self:GetSubjectPosition()
	local vecToSubject = (subjectPosition - game.Workspace.CurrentCamera.CFrame.p)
	local currLookVector = (vecToSubject * X1_Y0_Z1).unit
	local vrRotateInput = Vector2.new(rotateInput.x, 0)
	local startCFrame = CFrame.new(ZERO_VECTOR3, currLookVector)
	local yawRotatedVector = (CFrame.Angles(0, -vrRotateInput.x, 0) * startCFrame * CFrame.Angles(
		-vrRotateInput.y,
		0,
		0
	)).lookVector
	return (yawRotatedVector * X1_Y0_Z1).unit
end

function BaseCamera:GetHumanoid()
	local character = player and player.Character
	if character then
		local resultHumanoid = self.humanoidCache[player]
		if resultHumanoid and resultHumanoid.Parent == character then
			return resultHumanoid
		else
			self.humanoidCache[player] = nil -- Bust Old Cache
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				self.humanoidCache[player] = humanoid
			end
			return humanoid
		end
	end
	return nil
end

function BaseCamera:GetHumanoidPartToFollow(humanoid, humanoidStateType)
	if humanoidStateType == Enum.HumanoidStateType.Dead then
		local character = humanoid.Parent
		if character then
			return character:FindFirstChild("Head") or humanoid.Torso
		else
			return humanoid.Torso
		end
	else
		return humanoid.Torso
	end
end
