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)