--See: https://www.roblox.com/library/265487607/Cutter

local function GetCenterOfMass(parts)
	local TotalMass = 0
	local SumOfMasses = Vector3.new(0, 0, 0)

	for i = 1, #parts do
		local part = parts[i]
		
		TotalMass = TotalMass + part:GetMass()
		SumOfMasses = SumOfMasses + part:GetMass() * part.Position
	end
	
	return SumOfMasses/TotalMass, TotalMass
end

local function GetBackVector(CFrameValue)
	local _, _, _, _, _, r6, _, _, r9, _, _, r12 = CFrameValue:components()
	return Vector3.new(r6,r9,r12)
end

local function GetCFrameFromTopBack(CFrameAt, Top, Back)
	local Right = Top:Cross(Back)
	return CFrame.new(CFrameAt.x, CFrameAt.y, CFrameAt.z, Right.x, Top.x, Back.x, Right.y, Top.y, Back.y,Right.z, Top.z, Back.z)
end

local function GetRotationInXZPlane(cframe)
	local Back = GetBackVector(cframe)
	return GetCFrameFromTopBack(cframe.p, Vector3.new(0, 1, 0), Vector3.new(Back.x, 0, Back.z).unit)
end

