-1
\$\begingroup\$

In a game I'm toying with in Godot engine I have angles given in degrees in some places and angles given in radians in other places. Sometimes I need to mix both angles (ie. add them).

What built-in function allows me to convert degrees to radians (and the other way around)? Or is there none?

P.S. I realize that converting those is not rocket science and I could code something on my own, but Godot is already doing such conversions internally, so I would venture a guess that such function already exists.

\$\endgroup\$
  • 3
    \$\begingroup\$ I'm down-voting this question for not showing research effort. Even not knowing Godot, I was able to find the engine documentation, enter a search for the word "degrees," and find the methods Tyyppi_77 links below in seconds. Please take the time to do at least this level of investigation when faced with a game development problem. \$\endgroup\$ – DMGregory Sep 16 '17 at 12:05
  • \$\begingroup\$ @DMGregory I guess I couldn't find those, because I was searching for "radians" in the documentation. \$\endgroup\$ – jahu Sep 16 '17 at 12:08
  • 1
    \$\begingroup\$ Here are the search results for radians, which also include the hit that Tyyppi_77 links. \$\endgroup\$ – DMGregory Sep 16 '17 at 12:11
  • \$\begingroup\$ @DMGregory Then I guess I missed it (happens). P.S. I think our two comments in the middle can be deleted now. \$\endgroup\$ – jahu Sep 16 '17 at 12:13
  • 2
    \$\begingroup\$ I'm voting to close this question as off-topic because it's asking if "product X offers feature Y". \$\endgroup\$ – Alexandre Vaillancourt Sep 16 '17 at 13:31
7
\$\begingroup\$

This can be achieved using the deg2rad() and rad2deg functions.

Each function takes a float (the value being converted) and returns a float (the converted value).

\$\endgroup\$
-2
\$\begingroup\$

Some nodes in Godot 3.0 have a property rotation_degrees that you can use, i.e

# rotate the node a quarter turn using radians
my_2D_node.rotation += PI / 2
# read the current rotation in degrees
my_2D_node.rotation_degrees

The property rotation_degrees can be read and set, so you can for example write the property as .rotation in radians where convenient and somewhere else in the script read the property as .rotation_degrees if degrees would be more convenient. The object will do the conversion for you

\$\endgroup\$
  • 1
    \$\begingroup\$ This is a comment, not an answer \$\endgroup\$ – Kromster Nov 7 '18 at 6:45
  • \$\begingroup\$ You're not answering the question. The OP is asking the way to convert degree to radians and vice versa. \$\endgroup\$ – Emadpres Nov 7 '18 at 10:13
  • \$\begingroup\$ Arguably, this could be an answer in some contexts. If the reason you wanted to convert between degrees & radians was that all your math was in degrees, but the nodes only had a rotation_radians property, then learning about a rotation_degrees property could solve the problem by letting you skip the conversion entirely. I would recommend editing this answer to explain how to use this property to solve the problem, or converting it to a comment as suggested above. \$\endgroup\$ – DMGregory Nov 7 '18 at 13:08
  • \$\begingroup\$ I also thought this was an answer as I had the same question as the OP and found this to be my solution. I'll clarify how it could be used \$\endgroup\$ – oneindelijk Nov 12 '18 at 16:07

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.