@name Croco's Prop Thingie
@inputs V:vector
@outputs 
@persist E:entity Attack
@trigger 


Pos=E:pos()


if(owner():keyReload() & owner():aimEntity():owner() == owner()){
E=owner():aimEntity() 

}



    O=owner()
if(tickClk()){
    ##############################
    if(->V){
        Target=V
    }else{
        if(!O:keyUse()){
        Target=O:shootPos()+vec(0,0,200) # Above the owner's head.
    }elseif(O:keyUse()){
    Target=O:shootPos()+vec(0,0,0) # Above where the owner is looking.
    
}
}
    E:applyForce(((Target-E:pos())*10-E:vel())*E:mass()) #<-- makes E go to Target


    ##############################
}elseif(first()){
    E=entity()
    O=owner()
    runOnTick(1)
}



                #[STABILISE
                #TarQ = quat(O:shootPos()+vec(0,0,90)) #Calculate quaternion for target orientation
                CurQ = quat(E) #Calculate current orientation quaternion
                
                #TarQ/CurQ is a quaternion representing the rotation that will rotate the object from current orientation to the target one.
                Z = TarQ/CurQ
                
                #applyTorque() works on intrinsic vectors! Get the rotation vector and transform it.
                EP=E:pos()
                TTV = E:toLocal(rotationVector(Z)+EP)
                #Alternatively, can use "V = transpose(matrix(E))*rotationVector(Q)"
                
                #Apply torque. angVelVector() works like a delta term.
                #Factors 150 and 12 can be adjusted to achieve best effect.
                E:applyTorque((150*TTV - 12*E:angVelVector())*E:inertia())]#
                
                
                
                
                ###################################
                
                
        
