Get rotation_degrees from rotation

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

Hello!

In my game the player can rotate his/her robot’s arm towards the mouse with this code in the robot’s arm sprite:

rotation=(get_global_mouse_position()-get_node("..").position).angle()+135

But I would like get the angles to set shooting direction from it: when the arm points left, let the angle 180, when points up, let 90, etc.
How can I get these values? I tried switch with deg2rad and rad2deg from rotation, but I always get a very small or very large values.
The problem is the value of rotation_degrees doesn’t change during rotation and it is always the initial 180.
Or can I use the rotation_degrees somewhere in the above code to rotate the sprite in the direction of the mouse?

:bust_in_silhouette: Reply From: wyattb

So you are adding 135 degrees to the angle() radians? You need to convert the unit from one to the other if it will make sense.

Without this, the robot arm facing the opposite direction. I rotate the arm around point at its right side, not center or left side.

Tomi | 2021-06-17 13:40

This isn’t an answer. Add it as a comment and please delete this.

nahiyan | 2021-06-17 15:36

So you are adding 135 degrees to the angle() radians? You need to convert the unit from one to the other if it will make sense.

wyattb | 2021-06-17 13:57

:bust_in_silhouette: Reply From: bogdan000

The rotation variable contains the rotation angle in radians. rotation_degrees is the same value, but in degrees.

To convert from radians to degrees, you can use the rad2deg() function.

You can also just change rotation_degrees without touching rotation.
For example, if you want to make your player face the mouse, you can use this:

var angle = (get_global_mouse_position()-get_node("..").position).angle()
rotation_degrees = rad2deg(angle)

Aha. Thank you for your explanation! But interesting, when I use rad2deg(angle), I get a very large number as rotation_degrees, e.g.: 7644.299635.

Tomi | 2021-06-18 11:23

:bust_in_silhouette: Reply From: wyattb

So you are adding 135 degrees to the angle() radians? You need to convert the unit from one to the other if it will make sense.