@name liquid Mass physics inertia by leif
@inputs 
@outputs 
@persist Mul Z Gravity Scale Speed Mass Vec:vector G:array S:array ZZ:array Count Spread Random:vector
@trigger 
if(dupefinished()) {reset()}
if(first()) {
    Count=10
    Spread=0
    Scale=30
    Mass=200
    Speed=4
    Delay=0.1    
    for(R=1,Count) {    
        Random=randvec(vec(-Spread,-Spread,0),vec(Spread,Spread,0))
        holoCreate(R)    
        holoScaleUnits(R,vec(30,30,30))    
        holoPos(R,entity():pos()+vec(0,0,100+R*200*Delay)+Random)    
        holoModel(R,"hqsphere2")    
        holoAng(R,ang())
        holoMaterial(R,"models/props_lab/tank_glass001")
       
   }
    G=array()
    S=array()
    ZZ=array()
        
    Scales=vec(Scale,Scale,Scale)    
    Z=Scale   
        
    
}
runOnTick(1)
for(I=1,Count) {
    Ranger=rangerOffset(999,holoEntity(I):pos()+vec(0,0,2),holoEntity(I):pos()-vec(0,0,9999999999))
    
    
    Gravity=G[I,number]
    if(Ranger:distance()>4) {
        Vec=holoEntity(I):pos()+vec(0,0,Gravity)
    }else{
        Vec=Ranger:position()+vec(Ranger:hitNormal():x()*Speed,Ranger:hitNormal():y()*Speed,2)
    }
    
    
    if(Ranger:distance()<Scale/2) {
        if(Ranger:entity():isFrozen()==0) {
        Ranger:entity():applyOffsetForce(vec(0,0,-Mass),Ranger:position())
    }
        
        G[I,number]=-0.5
        holoAng(I,Ranger:hitNormal():toAngle()+ang(90,0,0))    
        S[I,number]=S[I,number]+1
        if(S[I,number]>Scale) {S[I,number]=Scale}
        
        ZZ[I,number]=Ranger:distance()*2
    } else{
        S[I,number]=S[I,number]-1
         
        ZZ[I,number]=ZZ[I,number]+1
        if(ZZ[I,number]>Scale) { ZZ[I,number]=Scale}
        if(S[I,number] <0) {S[I,number]=0}
        
        
        G[I,number]=G[I,number]-0.04
        
        if(G[I,number]<-9+(10/Scale)) {
            G[I,number]=-9+(10/Scale)
        }
    
    }
    Z=ZZ[I,number]
    Mul=S[I,number]
    Scales=vec(Scale+Mul,Scale+Mul,Z)
    holoScaleUnits(I,Scales)
    holoPos(I,Vec)
}

###notes
#Zis for the scale on the z axis, while mul is the scale on the x and y axis
#G is the gravitymultiplier
###the array s belongs to the mul scale multiplier
