Quaternion.Euler(歐拉角)c#
Quaternion qt = this.transform.rotation;
ide
Vector3 euler = qt.eulerAngles;post
Quaternion qt = Quaternion.AngleAxis( 50 , Vector3.up );this
至關於:Quaternion.Euler( 0 , 50, 0);orm
ps:z軸注視一個方向blog
1⃣️,沒有緩動get
this.transform.rotation = Quaternion.LookRotation(targetVec - this.transform.position);qt
至關於:this.transform.LookAt(targetVec - this.transform.postion);it
2⃣️,先快後慢io
Quaternion targetQt = Quaternion.LookRotation(targetVec - this.transform.position);
this.transform.rotation = Quaternion.Lerp( this.transform.rotation,targetQt, 0.1f );
3⃣️,勻速
Quaternion targetQt = Quaternion.LookRotation(targetVec - this.transform.position);
this.transform.rotation = Quaternion.RotateTowards( this.transform.rotation,targetQt, 0.1f );
float a = Quaternion.Angle( this.transform.rotation,targetQt );
if( a < = 2 ){
this.transform.rotation = targetQt;
}
1⃣️,right(無緩動)
this.transform.right = targetVec - this.transform.position;
2⃣️,FromToRotation(無緩動)
this.transtorm.rotation = Quaternion.FromToRotation( Vector3.right, targetVec );
例子:
①,分析,以下圖所示
a, 首先垂直向下打一條射線
b, 經過此射線可以獲得強面的法向量
c,獲得法向量, .....代碼以下:
void Update() { if (Input.GetMouseButtonDown(0))//監聽鼠標左鍵 { if (Physics.Raycast(this.transform.position, -Vector3.up, out this.hit, 100, this.layerMap))//向正下方發射光線檢測 { Quaternion qt = Quaternion.FromToRotation(Vector3.up, this.hit.normal);//以Y軸,法線旋轉 this.transform.rotation = qt; } } }
3⃣️, 緩動(套Lerp)