Godot 3.3.2 - Coordinates, Angles, and Signals

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

New to Godot and coming from a beginner+ Python background.

I have a block of code in a controller that should be adjusting an angle based on a destination variable. The signals appear to be working and setting the variable correctly, as I have them printing to the console:

SKILL 1 Dest: (1000, 440) # Correct
SKILL 1 Dest: (580, 440) # Correct and skill_1_dest was changed after signal was rec’d
Card 1, Skill 1, Pressed # Simple notification
SKILL 1 Dest: (1600, 700) # Manually set in code
SKILL 1 Angle: 0.007368 # This is the angle for (580, 440) not (1600, 700)

skill_1_dest = Vector2(1600,700) # Manually setting the destination
print("SKILL 1 Dest: " + str(skill_1_dest))
skill_1_angle = skill_1_loc.angle_to(skill_1_dest) # Is this the error?
skill_1_angle = skill_1_angle / -57.2958 # Adjusting for radians
print("SKILL 1 Angle: " + str(skill_1_angle))

skill_1_loc is static and never changes, its location is (580,640), which is directly below the destination (580, 440).

Am I using “angle_to” incorrectly? There is not much said in the documentation online:

What have I missed?

Thank you in advance,
-Mark

Hi,
what is the question? What do you expect from angle_to?

klaas | 2021-07-22 19:51

Like I had asked, am I using angle_to correctly?
I would expect that when the three different coordinates were input, the angle should have changed. However, it does not.

As I had noted:
SKILL 1 Angle: 0.007368 # This is the angle for (580, 440) not (1600, 700)
I.E. (580,640) to (580, 440), a straight line, however:

skill_1_dest = Vector2(1600,700) # Manually setting the destination
print("SKILL 1 Dest: " + str(skill_1_dest))
skill_1_angle = skill_1_loc.angle_to(skill_1_dest) # Is this the error?

Clearly, skill_1_dest is being set correctly, as it is printed to the console correctly.
However, the angle_to does not change from its result of “0.007368”

sivispacem | 2021-07-22 20:53

Do you mind the differents between

angle_to()

and

angle_to_point()

?

klaas | 2021-07-22 21:02

Are you asking as to whether I have read and understand the difference between the two methods? I have yes and I believe I do. I have tried both of these and they, essentially, produce the same result.

Let me approach this from a different way. I have three coordinates:
(580, 440) “to A”
(1000, 440) “to B”
(580,640) “from X”

What method will allow me to find the angle between the line drawn from X to either A or B? Or am I missing a step in my code and need to produce two lines and then find the angle?

Is there a method such as “line_to” to which I can pass coordinates to draw a line and then pass two lines to “angle_to” to derive the resulting angle?

Moreover, why, when changing the arg “skill_1_dest” in the line:

skill_1_angle = skill_1_loc.angle_to(skill_1_dest)

does the angle not change?

Thank you,
-Mark

sivispacem | 2021-07-23 16:27

you have to build the correct vectors first

var x = Vector2(100,50)
var A = Vector2(600, 50)
var B = Vector2(100,550)
var vector_of_x_to_A = A - x #build the vector pointing from x to A without any "offset"
print(vector_of_x_to_A)
var vector_of_x_to_B = B - x #build the vector pointing from x to B without any "offset"
print(vector_of_x_to_B)
print( vector_of_x_to_A.angle_to(vector_of_x_to_B)  * 180/PI ) #converted to degree for convenience

klaas | 2021-07-24 22:48