如何在godot引擎中确定Kinematic body相对于另一个Kinematic body的旋转角度?

问题描述 投票:0回答:0

有2架飞机,我需要AI控制的飞机,才能知道该转什么角度往玩家控制的飞机方向飞。 我没有找到关于这个主题的任何 youtube 视频。

这是我使用的代码:

var direction = (transform.origin - target.transform.origin).normalized()
# Calculate the angle between the direction vector and the object's current forward direction
var horizontal_angle = atan2(direction.x, direction.z) - rotation.y
var vertical_angle = atan2(direction.y, direction.z) - global_rotation.x

但是出了点问题,没有按预期工作。 结果,角度要么有错误的值,要么偏移,要么以不同的方式改变。

trigonometry game-development godot atan2
© www.soinside.com 2019 - 2024. All rights reserved.