@name awc_snake
@inputs 
@outputs 
@persist BAlpha BZ Smoother TargZ
@trigger 

runOnTick(1)

E = entity()
O = owner()

if(first()|dupefinished())
{
    function number awcApproach( Value:number, Target:number, Increment:number )
    {
        if( Value < Target)
        {
            if( (Value + Increment) < Target )
            {
                Value = Value + Increment
            }
            else
            {
                Value = Target
            }
        }
        elseif( Value > Target)
        {
            if( (Value + Increment) > Target )
            {
                Value = Value - Increment
            }
            else
            {
                Value = Target
            }
        }
        else
        {
            Value = Target
        }
        
        return Value
    }
    
    holoCreate(1)
#    holoModel(1, "models/props_junk/wood_crate002a.mdl")
    holoModel(1, "models/props_junk/cardboard_box002a.mdl")
    holoScaleUnits(1, vec(60,80,50))
#    holoParent(1, O)
}

Smoother = tickInterval() * 10

if(O:keyDuck() && O:isOnGround())
{
    TargZ = 30
    if(O:keyForward() || O:keyBack() || O:keyLeft() || O:keyRight())
    {
        TargZ = 45   
    }
    TargAlpha = 255
}
else
{
    TargZ = 200
    TargAlpha = 0
}

BZ = awcApproach(BZ, TargZ, abs(TargZ-BZ)*Smoother)
BAlpha = awcApproach(BAlpha, TargAlpha, Smoother*100)

OP = O:pos() + O:forward()*15
OA = O:eyeAngles()
TargPos = vec(OP:x(), OP:y(), OP:z() + BZ)
holoPos(1, TargPos)
holoAng(1, ang(0, OA:yaw()+90, OA:roll()+180))
holoAlpha(1, BAlpha)


