unity裏的向量

 

y                         = b                         + a * xorm

transform.position = transform.position + (mousPosition - transform.position.normalized * 0.1f);it

利用y = ax + b 這種直線方程來控制transform.position向mousPosition 慢慢移動。a(0.1f)爲時間io

 

用點乘求兩個向量夾角:form

Vector2 a = new Vector2 (1.0f,0.0f);
Vector2 b = new Vector2 (2.0f,2 * Mathf.Sqrt(3)).normalized;//必需要是normalized的才能這樣用 否的算出的結果會出錯
float d = Vector2.Dot (a,b);
float ang = Mathf.Acos (d) * Mathf.Rad2Deg;
Debug.Log (ang);transform

 

求兩個向量的距離 bug

Vector3 aa = new Vector3 (1, 0, 0);
Vector3 bb = new Vector3 (0,Mathf.Sqrt(3),0);
Debug.Log(Vector3.Distance (aa,bb));float

獲得2移動

 

向量差乘(計算兩個向量夾角)(這個沒看懂記住這種用法就好,實際使用的狀況較少)時間

Vector3 aa = new Vector3 (1, 1, 0);
Vector3 bb = new Vector3 (0,Mathf.Sqrt(3),0);
// Debug.Log(Vector3.Distance (aa,bb));
Vector3 c = Vector3.Cross (aa,bb);
Vector3 cc = Vector3.Cross (bb,aa);
float ang = Mathf.Asin (Vector3.Distance(Vector3.zero,Vector3.Cross(aa.normalized,bb.normalized)))*Mathf.Rad2Deg;
Debug.Log (ang);co

相關文章
相關標籤/搜索