@inputs
@outputs 
@persist Enemy:entity Self:entity 
@persist InertiaConstantRad:number TickTime:number
@persist InertiaConstantDeg:number
@trigger 
if (tickClk()) {

AimDir = Self:forward()
EnemyDir = Enemy:pos() - Self:pos()

#angle between where your aiming and where you want to aim
AngleToEnemy = acosr(AimDir:dot(EnemyDir)/(AimDir:length()*EnemyDir:length()))

#rotation dir is the direction of the rotation to be applied

AcE = AimDir:cross(EnemyDir)#aim cross multiplied with enemy
RotationDir = AcE / AcE:length()
RotationNeeded = RotationDir*AngleToEnemy

###Bring the velocity down to 0
SelfInertia = ang(Self:inertia():y(),Self:inertia():z(),Self:inertia():x())
Self:applyAngForce(SelfInertia*InertiaConstantDeg*(-Self:angVel()))
####


LocalRot = Self:toLocal(RotationNeeded+Self:pos())
Self:applyTorque(LocalRot*Self:inertia()*InertiaConstantRad/TickTime)
} elseif (first()) {
    Enemy = entity(149)
    Self = entity(151)
    InertiaConstantRad = 1550.027265
    InertiaConstantDeg = 27.053079273838
    TickTime = 0.015
    runOnTick(1)
}
