0 votes

I would like to calculate the angle between the two vectors of a dot product equation. The first vector is the source Node's facing vector or "front" vector. The second vector is the direction vector that points at the target Node from the source Node. For example:

var direction: Vector2 = $A.global_position.direction_to($B.global_position)
var facing: Vector2 = $A.global_transform.x
var dot: float = facing.dot(direction)
var degree: float = rad2deg(acos(dot))

This seems to work, but is there a different/better way? I found angle_to in the docs, which I don't fully understand, and angletopoint, which locks to the X-axis and won't work I don't think.

Godot version Godot Engine v3.5.1.stable.official
in Engine by (12 points)

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 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.