0 votes

the tittle says it all

Godot version 3.4.2
in Engine by (30 points)

2 Answers

+3 votes

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)



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

https://docs.godotengine.org/en/stable/classes/[email protected]?highlight=fmod#class-gdscript-method-fmod

by (19,300 points)
edited by
+1 vote


rotation_degrees = clamp(rotation_degrees, 0, 360)


rotation_degrees = wrapf(rotation_degrees, 0, 360)

or, as an integer,

rotation_degrees = int(rotation_degrees)%360
by (195 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.