I forgot to mention, that's not a gun but a rocket launcher With right click you zoom and aim. Then left click on the same time and the rocket starts in a straight line a little then heads towards the place where you aimed. It's a homing missle.
You can use the Z key to hide and lock the mouse in the window but targeting is done through a crosshair that depends on the forward direction of the camera and a raycast.
Unfortunately some objects had an uncentered pivot point and the rocket goes to that place, NOT where the object mesh is, but for the drone if you aim in the center the rocket will go there. Unfortunately the rocket has a very strong shield and only allows damage when it is close enough to the player and deactivates the shield.