在 Godot 中将 x/y 形式的 Vector 转换为 magnitude/angle

Converting Vector in x/y form to magnitude/angle in Godot

对于我开始制作的游戏,我必须学习矢量数学来计算力。要将向量从 x 和 y 转换为大小和角度,我已经读到我必须使用函数 tan^-1(y/x) 来表示角度。这是正确的吗?如果是的话,我该如何将其实现到 godots GDscript 中?

For a game that I am getting started making I have had to learn vector math to calculate forces.

首先,这不一定是真的。根据您的用例,使用 Rigid Bodies 并让 Godot 为您计算力的影响可能是最有效的。

To convert a vector from x and y to magnitude and angle I have read that I for the angle have to use the function tan^-1(y/x).

要将矢量从 x 和 y 转换为大小和角度,请使用 Vector2.length() and Vector2.angle()

话虽这么说,如果你想学习向量数学,那就去做吧! Godot 有它的 own vector math docs,我相信您可以在网上找到很多其他类似的课程。 但是,很高兴知道该引擎为您提供了大部分此类功能。 编写一堆矢量数学而不是仅仅调用一个 bultin 函数只会让你的代码更复杂。