local function t(t)local o=0 local n=Vector3.new(0,0,0)for P=1,#t,1 do local b=t[P]o=o+b:GetMass()n=n+b:GetMass()*b.Position end return n/o,o end local function o(t)local o,n,P,b,d,M,h,I,E,u,H,x=t:components()return Vector3.new(M,E,x)end local function n(t,o,n)local P=o:Cross(n)return CFrame.new(t.x,t.y,t.z,P.x,o.x,n.x,P.y,o.y,n.y,P.z,o.z,n.z)end local function P(t)local P=o(t)return n(t.p,Vector3.new(0,1,0),(Vector3.new(P.x,0,P.z)).unit)end
--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
