@name EPIC turret
@inputs A:entity Range
@outputs Fire NextTarg V:vector
@persist Ang:angle Plate:entity User:entity Pos:vector Gyro:angle


if(first())
{
    runOnTick(1)
    
    Me = owner()

    Plate = entity()
    
    
    Pos = entity():pos() + vec(0,0,0)

}

Target = A:toWorld(vec(0,-A:pos():y(),A:height()/2))

P = Plate:elevation(Target)
Y = Plate:bearing(Target)
R = Plate:angles():roll()

Gyro = (-ang(P,Y,R+90)*100)

Plate:applyAngForce( Gyro + $Gyro*5)

V = (Pos - Plate:pos())*100

Plate:applyForce(V + $V*5)

Ang = Plate:angles()

#Plate:applyAngForce()

Fire = (A&Range)
NextTarg = !NextTarg*(A:health() <= 0)
