@name HoloMomentumSimu
@persist Count
@persist E:entity
@persist [MainStyle SubStyle]:table

if(first())
{
    E = entity()
    
    MainStyle = table(
        array(
            vec(3),
            vec(255, 0, 0),
            "hq_sphere",
            1
        ),
        array(
            "no"
        )
    )
    
    SubStyle = table(
        array(
            vec(0.5),
            vec(255, 100, 0),
            "hq_sphere",
            1
        ),
        array(
            10, 0, 3,
            "effects/beam_generic01",
            vec(255), 255
        )
    )
    
    function createMBody(Index, Pos:vector, Style:table)
    {
        local H = holoCreate(Index, Pos, Style[1, array][1, vector], ang(), Style[1, array][2, vector], Style[1, array][3, string])
        
        holoDisableShading(1, Style[1, array][4, number])
        
        if(Style[2, array][1, string] != "no")
        {
            H:setTrails(Style[2, array][1, number], Style[2, array][2, number],
                        Style[2, array][3, number], Style[2, array][4, string],
                        Style[2, array][5, vector], Style[2, array][6, number])
        }
    }
    
    function handleMBody(Index, TargetPos:vector, ForceMult, Drag)
    {
        local H = holoEntity(Index)
        
        local ApplyForce = (TargetPos - H:pos()) * ForceMult
        
        H["vel", vector] = (H["vel", vector] + ApplyForce) * Drag
        
        holoPos(Index, H:pos() + H["vel", vector])
    }
    
    #Central Holo
    createMBody(1, E:toWorld(vec(0, 0, 100)), MainStyle)
    
    #Orbiting Holos
    Count = 5
    
    for(I = 2, Count + 1)
    {
        createMBody(I, holoEntity(1):pos() + randvec(-100, 100), SubStyle)
    }
}

interval(100)

#TargetPos = owner():keyUse() ? (owner():aimPos() - (owner():eye() * 25)) : (owner():shootPos() + vec(0, 0, 15) + (owner():eye() * 15))

handleMBody(1, E:toWorld(vec(0, 0, 100)), 0.5, 0.6)

for(I = 2, Count + 1)
{
    handleMBody(I, holoEntity(1):pos(), 0.5, 1)
}
