Well, I'm a little unclear on what your question is. Do you just want the gun to point at the mouse, or are you trying to actually have the gun's position, constrained by a specified perimeter, around your player?
Or both?
For starts, to fix that rotation bit, I'd just rewrite the code as :
onready var gun = $AnimatedSprite/Gun
func _physics_process(delta):
get_input()
move_weapon()
func move_weapon():
gun.rotation = gun.position.get_angle_to(get_local_mouse_position())
Or, even easier:
func move_weapon():
gun.look_at(get_local_mouse_position())
And, if you do want it be constrained by an orbit around the player, I'd use something like:
onready var gun = $AnimatedSprite/Gun
var perimeter_radius:float
func _physics_process(delta):
get_input()
move_weapon()
func move_weapon():
gun.position.x = clamp(gun.position.x, player.position.x-perimeter_radius, player.position.x+perimeter_radius)
gun.position.y= clamp(gun.position.y, player.position.y-perimeter_radius, player.position.y+perimeter_radius)
gun.look_at(get_local_mouse_position()