如何计算敌人与玩家之间的角度

时间:2019-02-09 19:02:22

标签: unity3d angle

我如何计算敌方坦克与我之间的度数角度?我在坦克上开火,我需要计算角度。我的位置来自Physics.Raycast。我尝试了Vector3.Angle(),但是生成的角度值错误。敌方坦克的位置不同,我需要在当地空间计算。 我的代码是通过统一文档(here is link)尝试过Vector3.Angle()

 if (Physics.Raycast(_startPositionTransform.position, _startPositionTransform.forward, out hitInfo))
     {
         Debug.Log("Detecting collision with: " + hitInfo.transform.name);

         Vector3 direction =  _startPositionTransform.position - hitInfo.transform.position;

         float angle = Vector3.Angle(direction, hitInfo.transform.forward);

         Debug.Log("Angle is : " + angle);



     }

图片示例: example picture

感谢您的建议。

0 个答案:

没有答案