public class script : MonoBehaviour
{//定义一个玩家一个敌人
public Transform t1;
public Transform t2;
// Start is called before the first frame update
void Start()//方法
{
float dot = Vector3.Dot(t1.position.normalized, t2.position.normalized);
float angle = Mathf.Acos(dot) * Mathf.Rad2Deg;
Vector3 corss = Vector3.Cross(t1.position.normalized, t2.position.normalized);
if(corss.y<0)
{
angle = 360 - angle;
}
Debug.DrawLine(Vector3.zero, corss, Color. red);
//this.transform.forward获取物体的正前方
//this.transform.right
//this.transform.up
}
// Update is called once per frame
void Update()
{
}
}
点乘(dot product)
又叫内积/数量积,记作 (也有人习惯写作 ),点乘的结果是个标量(scalar),它的几何意义是 向量a在向量b上的投影长度 乘以 向量b的长度,
叉乘(cross product)
向量积,数学中又称外积、叉积,物理中称矢积、叉乘,是一种在向量空间中向量的二元运算。与点积不同,它的运算结果是一个向量而不是一个标量。并且两个向量的叉积与这两个向量和垂直。