-- Computes the look-angle to be used by the client.
-- If no lookVector is provided, the camera's lookVector is used instead.
-- useDir (-1 or 1) can be given to force whether the direction is flipped or not.


function CharacterRealism:ComputeLookAngle(lookVector, useDir)
	local inFirstPerson = FpsCamera:IsInFirstPerson()
	local pitch, yaw, dir = 0, 0, 1
	
	if not lookVector then
		local camera = workspace.CurrentCamera
		lookVector = camera.CFrame.LookVector
	end
	
	if lookVector then
		local character = self.Player.Character
		local rootPart = character and character:FindFirstChild("HumanoidRootPart")
		
		if rootPart and rootPart:IsA("BasePart") then
			local cf = rootPart.CFrame
			pitch = -cf.RightVector:Dot(lookVector)
			
			if not inFirstPerson then
				dir = math.clamp(cf.LookVector:Dot(lookVector) * 10, -1, 1)
			end
		end
		
		yaw = lookVector.Y
	end
	
	if useDir then
		dir = useDir
	end
	
	pitch *= dir
	yaw *= dir
	
	return pitch, yaw
end
