@name Bubble Buddy
@inputs A:entity
@outputs
@persist P Y R V:vector

interval(1)

if(first()) {findByModel("models/hunter/misc/sphere175x175.mdl")}
findSortByDistance(entity():pos())

E = find()

P = angnorm(entity():angles():pitch()-A:eye():toAngle():pitch())
Y = angnorm(entity():angles():yaw()-A:eye():toAngle():yaw())
R = angnorm(entity():angles():roll()-A:eye():toAngle():roll())
V = A:shootPos() - E:massCenter()
Pitch = P*2 + $P*10
Yaw = Y*2 + $Y*10
Roll = R*2 + $R*10

if(!E:isPlayerHolding()&A) {
    E:applyOffsetForce(entity():up()*Pitch*E:mass()/2,E:massCenter()+entity():forward()*(32))
    E:applyOffsetForce((-1)*entity():up()*Pitch*E:mass()/2,E:massCenter()+entity():forward()*(-32))

    E:applyOffsetForce(entity():up()*Roll*E:mass()/2,E:massCenter()+entity():right()*(32))
    E:applyOffsetForce((-1)*entity():up()*Roll*E:mass()/2,E:massCenter()+entity():right()*(-32))

    E:applyOffsetForce(entity():right()*Yaw*E:mass()/2,E:massCenter()+entity():forward()*(32))
    E:applyOffsetForce((-1)*entity():right()*Yaw*E:mass()/2,E:massCenter()+entity():forward()*(-32))
    
    E:applyForce(V*10*E:mass() + $V*20*E:mass())
}
