-- Mounts the provided humanoid into the look-angle
-- update system, binding all of its current and
-- future Motor6D joints into the rotator.


function CharacterRealism:MountLookAngle(humanoid)	
	local character = humanoid.Parent
	local rotator = character and self.Rotators[character]
	
	if not rotator then
		-- Create a rotator for this character.
		rotator = 
		{
			Motors = {};
			
			Pitch =
			{
				Goal = 0;
				Current = 0;
			};

			Yaw =
			{
				Goal = 0;
				Current = 0;
			};
		}
		
		-- If this is our character, the rotation 
		-- values should not be interpolated while 
		-- the client is in first person.
		
		local player = Players:GetPlayerFromCharacter(character)
		
		if player == self.Player then
			rotator.SnapFirstPerson = true
		end
		
		-- Register this rotator for the character.
		self.Rotators[character] = rotator
		
		-- Record all existing Motor6D joints
		-- and begin recording newly added ones.
		
		local function onDescendantAdded(desc)
			if desc:IsA("Motor6D") then
				self:AddMotor(rotator, desc)
			end
		end
		
		for _,desc in pairs(character:GetDescendants()) do
			onDescendantAdded(desc)
		end
		
		rotator.Listener = character.DescendantAdded:Connect(onDescendantAdded)
	end
	
	return rotator
end
