Make a smoother rotation to a point ( 2D )

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BarbOn
func point_at():
    var player_aim_angle
    player_aim_angle=get_node("Player/Hand").get_angle_to(get_global_mouse_position())
    if(get_node("Player/Hand").rotation_degrees!=player_aim_angle&&is_mouse_in==false):
	    get_node("Player/Hand").rotate(player_aim_angle)

There is a smoother way to rotate an object ( in this case to the mouse pointer ) ?
Here’s a video:

:bust_in_silhouette: Reply From: Dlean Jeans

Rotate with smaller angle:

$Player/Hand.rotate(player_aim_angle * .1)

or better, use angle lerping:

func point_at():
    ...
    $Player/Hand.rotation = lerp($Player/Hand.rotation, player_aim_angle, 0.1)

func lerp_angle(from, to, weight):
    return from + short_angle_dist(from, to) * weight

func short_angle_dist(from, to):
    var max_angle = PI * 2
    var difference = fmod(to - from, max_angle)
    return fmod(2 * difference, max_angle) - difference

thanks for the help

BarbOn | 2019-06-18 13:40