@name 
@inputs 
@outputs TarPos:vector
@persist E:entity Size Walk_i Walk Holo_head_ang:angle Fly EE:entity
@trigger 
@model models/kobilica/relay.mdl
interval(50)
if(first() | duped())
    {
    
    Size=0.25
    E=entity()
    E:setAlpha(0)
    E:setMass(50)
    
    holoCreate(0,E:pos(),vec(4,3,2)*Size,E:angles(),vec(250,190,190))
    holoParent(0,E)
    holoCreate(1,E:toWorld(vec(3,0,1)*6*Size),vec(2,2,2)*Size,E:angles())
    holoParent(1,0)
    holoAlpha(1,0)
    holoCreate(2,E:toWorld(vec(5,0,1)*6*Size),vec(2,2,2)*Size,E:angles(),vec(250,190,190))
    holoParent(2,1)

    holoCreate(3,E:toWorld(vec(2.4,1.8,-3.5)*6*Size),vec(1.2,1.2,2)*Size,E:angles(),vec(250,190,190))
    holoParent(3,0)
  holoCreate(4,E:toWorld(vec(2.4,-1.8,-3.5)*6*Size),vec(1.2,1.2,1.5)*Size,E:angles(),vec(250,190,190))
    holoParent(4,0)
  holoCreate(5,E:toWorld(vec(-2.8,1.8,-3.5)*6*Size),vec(1.2,1.2,1.5)*Size,E:angles(),vec(250,190,190))
    holoParent(5,0)
  holoCreate(6,E:toWorld(vec(-2.8,-1.8,-3.5)*6*Size),vec(1.2,1.2,1.5)*Size,E:angles(),vec(250,190,190))
    holoParent(6,0)


    holoCreate(7,E:toWorld(vec(6.9,2-0.3,1.5)*6*Size),vec(1,2,2)*Size*(1/8),E:angles(),vec())
    holoParent(7,1)
    holoCreate(8,E:toWorld(vec(6.9,2-0.8,1.5)*6*Size),vec(1,2,2)*Size*(1/8),E:angles())
    holoParent(8,1)
    holoCreate(9,E:toWorld(vec(6.9,-2+0.3,1.5)*6*Size),vec(1,2,2)*Size*(1/8),E:angles(),vec())
    holoParent(9,1)
    holoCreate(10,E:toWorld(vec(6.9,-2+0.8,1.5)*6*Size),vec(1,2,2)*Size*(1/8),E:angles())
    holoParent(10,1)
    
    holoCreate(11,E:toWorld(vec(6.9,-0.7,0.5)*6*Size),vec(1,2,2)*Size*(1/8),E:angles(),vec(250,190,190)/2)
    holoParent(11,1)
    holoCreate(12,E:toWorld(vec(6.9,0.7,0.5)*6*Size),vec(1,2,2)*Size*(1/8),E:angles(),vec(250,190,190)/2)
    holoParent(12,1)
    
    for(I=0,12){
        holoMaterial(I,"models/debug/debugwhite")
        }
        
        
    holoPos(0,E:toWorld(vec(0,0,7)))
    }
if(random(100)>97 | EE)
    {

    findIncludePlayer("snow")
    findExcludeEntity(E)
    findInSphere(E:pos(),9999999)
    EE=find()
    if(EE)
        {
        TarPos=EE:pos()+vec(0,0,-5)
        }
    else
        {
        soundPlay(0,1,"ambient/sheep.wav")
    soundPitch(0,80+random(40))
        rangerFilter(E)
        R_r=rangerOffset(random(100),E:pos(),vec(1,0,0):rotate(0,random(360),0))

        TarPos=R_r:position()
        }
    }
Speed=E:vel():length()/17
Fly=abs(E:vel():z())>4
#TarPos=owner():shootPos()

Tar_dist=TarPos-E:pos()
Tar_dist2=Tar_dist:length()
Tar_ang=Tar_dist:toAngle()
Tar_sin=sin(Tar_ang:yaw()-E:angles():yaw())
Walk=Tar_dist2>20
Walk_i+=17
Walk_sin=sin(Walk_i)*35*Speed
Walk_p1=vec(0,0,-1.2):rotate(Walk_sin,0,0)
Walk_p2=vec(0,0,-1.2):rotate(-Walk_sin,0,0)
holoPos(3,E:toWorld((vec(2.4,1.8,3)+Walk_p1)*6*Size))
holoAng(3,E:toWorld(ang(Walk_sin,0,0)))

holoPos(4,E:toWorld((vec(2.4,-1.8,3)+Walk_p2)*6*Size))
holoAng(4,E:toWorld(ang(-Walk_sin,0,0)))


holoPos(5,E:toWorld((vec(-2.8,1.8,3)+Walk_p2)*6*Size))
holoAng(5,E:toWorld(ang(-Walk_sin,0,0)))

holoPos(6,E:toWorld((vec(-2.8,-1.8,3)+Walk_p1)*6*Size))
holoAng(6,E:toWorld(ang(Walk_sin,0,0)))
Holo_head_ang=ang(Tar_ang:pitch(),Holo_head_ang:yaw()+sin(Tar_ang:yaw()-Holo_head_ang:yaw())*34,0)

holoAng(1,Holo_head_ang)
if(!Fly)
{
if(Walk)
{
E:applyForce((Tar_ang:forward()*3000 -E:vel()*80)*vec(1,1,1))
}
if(Walk|abs(Tar_sin)>0.7)
    {
    E:applyAngForce(-E:angles()*ang(1,0,1)*130+ang(0,Tar_sin,0)*10000 -E:angVel()*10)
    }
}


