local function b(b)local S=0 local G=Vector3.new(0,0,0)for g=1,#b,1 do local f=b[g]S=S+f:GetMass()G=G+f:GetMass()*f.Position end return G/S,S end local function S(b)local S,G,g,f,r,d,a,K,q,s,w,Q=b:components()return Vector3.new(d,q,Q)end local function G(b,S,G)local g=S:Cross(G)return CFrame.new(b.x,b.y,b.z,g.x,S.x,G.x,g.y,S.y,G.y,g.z,S.z,G.z)end local function g(b)local g=S(b)return G(b.p,Vector3.new(0,1,0),(Vector3.new(g.x,0,g.z)).unit)end

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

