How do I Clamp an Angle properly

Godot Version

4.5

Question

When I’m using angle_lerp() it fixes my lerping angle problems and allows the angle to go past a 360. I want to clamp my angle so I tried this

‘‘‘body_final_rotation = clamp(body_final_rotation, rotation.y - deg_to_rad(90), rotation.y + deg_to_rad(90))’’’

But this doesn’t work well because when the angle rotation.y goes past 360 the clamp clamps “body_final_rotation” to the other side.

Is there any way I could make something like angle_lerp() but for clamp()? like some kind of angle_clamp()?


Cant you use max as the parameters? I assume you want min to be 0 and max to be back to 0.

So something like max(rotation.y, 0) and max(rotation.y, 360)