How do radians work in godot?

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

I’ve seen a couple tutorials use radians instead of degrees, but I’ve been trying to figure out how exactly this works out…

I mean, a random equation like PI/6 * velocity.y/jump_impulse doesn’t really make sense to a beginner now does it?

So can someone explain how exactly radians work in godot? is it like an invisible circle drawn around the node? And what’s with the use of PI? How can I use degrees in the above equation?

tl;dr : Can someone please just explain to me how radians work?

:bust_in_silhouette: Reply From: kyuth

Radians and degrees are two different ways to say the same thing.

If you turn 90 degrees, you turn PI / 2 radians (1.570…).
If you turn 180 degrees, you turn PI radians (3.141…).
If you turn 360 degrees, you turn 2 * PI radians (6.283…).

Math works with radians only. There shouldn’t be any reason to use degrees in code.

However most people learn degrees first and think in degrees instead of in radians. Because of that the web is full of code examples where degrees are turned to radians and vice versa and that causes a lot of confusion. What everyone should do instead is to start to think in radians when writing a code. Then there is no need to do conversions and code will be faster and easier to understand. It takes some time to get used to it but it’s worth it.

However degrees can be useful in other situations, for example if you need to rotate something in Godot editor, for example 90 degrees, it is easier to write 90 to rotation box instead of writing something like 1.570…

So is there like a theoretical circle around the node?

Attaboi12345 | 2023-01-29 17:06

2 Likes
:bust_in_silhouette: Reply From: SteveSmith

Radians are just another measurement of turning like degrees. 360deg = PI*2 radians. 180deg = PI radians. PI/6 radians = 30deg. There are also functions deg2rad and rad2deg to convert between the two.

Thank you, quick easy explanation that makes sense.