How can my rotation snap like a grid to a mouse position?

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

The rotation of the object is the same as the mouse position

func _process(_delta):
if Input.is_action_pressed("click") && mouse_over1:
	look_at(get_global_mouse_position())

How can I make it so that the rotation of the object is still based on the mouse position but it locks to a grid by 30?

enter image description here

I am trying to snap the hand to the highlighted spots
Thanks for any help

:bust_in_silhouette: Reply From: CassanovaWong

something like:

if rad2deg(global_position.get_angle_to(get_global_mouse_position()) % 30 == 0:
  look_at(get_global_mouse_position())