How to smooth rotate to mouse position

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By HolyAlloy

I tried it first, but it not work for me:

var mouse_dir = (get_global_mouse_position() - $Tank_gun.global_position).normalized()
var corrent_dir = Vector2(-1, 0).rotated($Tank_gun.global_rotation)

$Tank_gun.global_rotation = corrent_dir.linear_interpolate(-mouse_dir, 50 * delta).angle()

Use in _physics_process

:bust_in_silhouette: Reply From: flurick
var m = get_global_mouse_position()
var aim_speed = deg2rad(1)
if $Tank_gun.get_angle_to(m) > 0:
	$Tank_gun.rotation += aim_speed
else:
	$Tank_gun.rotation -= aim_speed