system
June 17, 2021, 9:48am
1
Attention
Topic was automatically imported from the old Question2Answer platform.
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?

system
June 17, 2021, 1:20pm
2
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.

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

system
June 17, 2021, 3:36pm
3
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.

system
June 17, 2021, 6:29pm
4
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.