-- Register's a newly added Motor6D  
-- into the provided joint rotator.


function CharacterRealism:AddMotor(rotator, motor)
	local parent = motor.Parent
	
	if parent and parent.Name == "Head" then
		parent.CanCollide = true
	end
	
	-- Wait until this motor is marked as active
	-- before attempting to use it in the rotator.
	
	Util:PromiseValue(motor, "Active", function ()
		local data = 
		{ 
			Motor = motor;
			C0 = motor.C0;
		}
		
		-- If it can be found, use the source RigAttachment for this Motor6D
		-- joint instead of using the static C0 value. This is intended for R15.
		
		Util:PromiseChild(motor.Part0, motor.Name .. "RigAttachment", function (origin)
			if origin:IsA("Attachment") then
				data.Origin = origin
				data.C0 = nil
			end
		end)
			
		-- Add this motor to the rotator
		-- by the name of its Part1 value.
		
		local id = motor.Part1.Name
		rotator.Motors[id] = data
	end)
end
