Okay, I pretty much did a Lua overhaul on this. There are now two modes you can switch between by tapping the Pie Menu button: fixed and movable.
In movable mode, whenever you aim (sharp stance), the floating gun will move slightly forward and up a little bit. This puts it slightly more directly over your held gun, so the floating gun's shots will line up more accurately. Also if you aim up at a high angle, the floating gun will move behind you so it doesn't get in the way of your shots. When you line a target up in your sights, the gun will move up a bit and track the target directly, instead of a position near the target.
Here's a small demonstration of it:
Phew. This is the most complex Lua mod I've done so far. I don't think I can even understand my own code at this point, since I keep building onto it
.