@name Center of Mass System Finder
@inputs 
@outputs CoG:vector On
@persist Contrap:array CoG1:vector CoG2:vector CoG:vector C N1 N
@trigger all
Time=20
interval(Time)

Self=entity():owner()
Chat = Self:lastSaid()
K = curtime() - entity():owner():lastSaidWhen() < (Time*2)/1000
Lock=Chat:find("lockon")

if(Lock&K){N1=N
N=Self:aimEntity():id()
print(N+":"+N1)
}
if(Chat:find("cogon")){On=1}
if(Chat:find("cogoff")){On=0}
On=1


if(N1!=N){C=1 Contrap=entity(N):getConstraints()}


while(C<Contrap:count()){
    print("C="+C)
    if(C==1){M=entity(N):mass() 
    D=entity(N):pos()-entity():massCenter()}
    if(C>1){M=Contrap:entity(C):mass()
D=Contrap:entity(C):pos()-entity():massCenter()}
    CoG1+=M*D
    CoG2+=M
    C+=1
}

if(C>Contrap:count()){CoG=CoG1/CoG2 }
if (Chat:find("sum")&K){
    print("Center of Gravity: "+CoG)
    print(M+"*"+D+"/"+M)
    print("Count: "+Contrap:count())
    }
