当前位置:   article > 正文

关于Unity向量的点积的问题_unity 点积

unity 点积
 public Transform target;
    // Start is called before the first frame update
    void Start()
    {
        //点乘的几何意义
        //在自己向量上投影的长度
        //点乘结果>0 两个向量夹角为锐角
        //点乘结果=0两个向量为直角
        //点乘结果<0两个向量夹角为钝角
        //我们可以用这个规律判断地方的大致方位
        
    }

    // Update is called once per frame
    void Update()
    {
        画线段 前两个参数分别是起点和终点
        //Debug.DrawLine(this.transform.position, this.transform.position + this.transform.forward, Color.red);
        /画射线 前两个参数是起点和方向
        //Debug.DrawRay(this.transform.position, this.transform.forward, Color.white);

        float dotResult = Vector3.Dot(this.transform.forward, target.position - this.transform.position);
        if(dotResult>=0)
        {
            Debug.Log("他在我前方");
        }
        else
        {
            Debug.Log("他在我后方");
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

关于点积的一些用法

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/756486
推荐阅读
相关标签
  

闽ICP备14008679号