Infinite rotation_degrees using look_at function

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

Hi, i am making a game in which you use a gun that looks at the mouse. it follows the mouse nicely, but i need to get the exact rotation of the gun to calculate the knock back and the value exceeds 360 and goes on as i rotate it.

here’s the code:

    look_at(get_global_mouse_position())
	if get_global_mouse_position().x > global_position.x:
		sprite.flip_v = false
	if get_global_mouse_position().x < global_position.x:
		sprite.flip_v = true
:bust_in_silhouette: Reply From: jgodfrey

You can wrap the gun’s rotation within a defined range via the fmod method. You probably want something like this:

var wrapped_rotation = fmod(rotation_degrees, 360))

Thanks, i have already solved it using

rotation = rotation%360

or something like that

Ludows | 2022-12-27 09:45