7
\$\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\$
7
  • 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, 2017 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, 2017 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, 2017 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, 2017 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\$
    – Vaillancourt
    Sep 16, 2017 at 13:31

2 Answers 2

18
\$\begingroup\$

This can be achieved:

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

\$\endgroup\$
0
\$\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\$
4
  • 1
    \$\begingroup\$ This is a comment, not an answer \$\endgroup\$
    – Kromster
    Nov 7, 2018 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, 2018 at 10:13
  • 1
    \$\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, 2018 at 13:08
  • 1
    \$\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\$ Nov 12, 2018 at 16:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .