################
# > Bob Pet Ghost: An annoying ghost who will follow you.
# > How to use: Spawn it.
################

@name Pet Ghost
@outputs BodyPos:vector OPos:vector Distance Timer

interval(10)

if (first()) {
    holoCreate(0)
    holoCreate(1)
    holoCreate(2)
    holoScale(0, vec(2.5,2.5,8))
    holoScale(1, vec(1.5,1.5,1.5))
    holoScale(2, vec(1.9,1.9,1.9))
    holoPos(0, entity():pos())
    holoPos(1, entity():pos()+vec(0,0,57))
    holoPos(2, entity():pos()+vec(0,0,57))
    holoModel(0, "dome")
    holoModel(1, "hqsphere2")
    holoModel(2, "hqsphere2")
    holoAlpha(0, 70)
    holoAlpha(1, 150)
    holoAlpha(2, 70)
    holoParent(1, holoEntity(0))
    holoParent(2, holoEntity(0))
    Body = holoEntity(0)
    BodyPos = holoEntity(0):pos()
}

O = owner()
OPos = O:pos()
Distance = BodyPos:distance(OPos)

if (Distance > 75) {
    BodyPos-=holoEntity(0):angles():forward()*(Distance/100)+Body:vel():length()
}

holoPos(0, BodyPos)
holoAng(0, (BodyPos - OPos):toAngle())

Timer+=1

if (Timer > 500) {
    holoEntity(1):soundPlay("whereareyoutakingme?",5,"vo/trainyard/man_whereyoutakingme.wav")
    Timer = 0
}
