–1 vote

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 skill1dest 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:
https://docs.godotengine.org/en/stable/classes/class_vector2.html#class-vector2-method-angle-to

What have I missed?

Thank you in advance,
-Mark

Godot version 3.3.2
in Engine by (11 points)

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

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"

Do you mind the differents between

angle_to()

and

angle_to_point()

?

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

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

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.