0 votes

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?

Godot version 3.3 Stable Official Win64
in Engine by (48 points)

3 Answers

0 votes

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.

by (805 points)
edited by

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

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.

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

+1 vote

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)
by (46 points)

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.

0 votes

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.

by (805 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.