how do i keep rotation degrees between 0 and 360

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

the tittle says it all

:bust_in_silhouette: Reply From: jgodfrey

Depending on the details, you might be after fmod(). For example:

func _ready():
	for deg in [0, 250, 359, 360, 400]:
	   deg = fmod(deg, 360)
	   print(deg)

prints…

0
250
359
0
40

If you also want to push negative angles back into the 0-360 range, you can just add an additional check after the fmod call. Something like this:

deg = fmod(deg, 360)
if deg < 0: deg += 360

:bust_in_silhouette: Reply From: CassanovaWong

maybe:

rotation_degrees = clamp(rotation_degrees, 0, 360)

or

rotation_degrees = wrapf(rotation_degrees, 0, 360)

or, as an integer,

rotation_degrees = int(rotation_degrees)%360