Vector3.Angle
Vector3.Angle(A.posion,B.position);
Vector3.Angle(B.position-A.posion,B.position-C.position);
Vector3.Cross
求兩個(gè)向量的法向量
Debug.DrawLine(B.position,Vector3.Cross(B.position-A.posion,B.position-C.position));
三角形ABC圍繞頂點(diǎn)B旋轉(zhuǎn)淀零,三條邊都在跟隨旋轉(zhuǎn)。就可以使用這個(gè)求出旋轉(zhuǎn)頂點(diǎn)的法向量以此來實(shí)時(shí)監(jiān)測三角形的每條邊的是否正確的跟隨旋轉(zhuǎn)吮播。實(shí)現(xiàn)三角液壓器算法就可以用這個(gè)挖藏。當(dāng)然也需要判斷旋轉(zhuǎn)角度的正負(fù)最楷。
Vector3.Dot
可以用來判斷一個(gè)物體相對于另一個(gè)物體的位置,因?yàn)?strong>a·b=|a||b|cos<a,b>,當(dāng)然用mathf.acos與vector3.normalize,也可以求出角度铲敛。
Vector3 dir=transform.TransformDirction(Vector3.forward);//這里可是任何方向
Vector3 toOther = other.position - transform.position;
if ((forward, toOther) < 0)
print("The other transform is behind me!");
換而言之上面這個(gè)就是求other在transform正方向上的投影褐澎。然后根據(jù)角度就可以判斷出是否在一條線上。當(dāng)然標(biāo)準(zhǔn)化了的兩個(gè)向量點(diǎn)乘伐蒋,在一個(gè)正方向返回就是1工三,反方向返回就是-1迁酸。