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("他在我后方");
}
}
关于点积的一些用法