Quaternion常见方法

        (1)Quaternion.AngleAxis(30,Vector3.left),绕X轴旋转-30度(Vector3.right:30度),以此类推

        (2)SetLookRotation(Vector3 v1),设置Quaternion实例的朝向(Z轴)与向量v1指向的方向相同

Quaternion quaternion = Quaternion.identity;
quaternion.SetLookRotation(Vector3.right);
transform.rotation = quaternion;//Z轴朝向Vector3.right

        SetLookRotation(Vector3 v1, Vector3 v2),设置z轴方向与v1相同,x轴垂直于由Vector3.zero、v1、v2构成的平面。v2决定了y轴的朝向

Quaternion quaternion = Quaternion.identity;
quaternion.SetLookRotation(Vector3.right,Vector3.forward);
transform.rotation = quaternion;

        (3)LookRotation与SetLookRotation功能一样

        (4)SetFromToRotation(Vector3 fromDirection, Vector3 toDirection),创建一个从向量fromDirection到向量toDirection的旋转(首先将对象自身坐标系x、y、z轴方向和世界坐标系的x、y、z轴方向一致,然后将对象自身坐标系中fromDirection指向的方向旋转到toDirection)

Quaternion quaternion = Quaternion.identity;
quaternion.SetFromToRotation(Vector3.right, Vector3.forward);//自身Vector3.right指向方向转到Vector3.forward
transform.rotation = quaternion;

        (5)FromToRotation与SetFromToRotation功能一样
        (6)RotateTowards(Quaternion from, Quaternion to, float maxDegreesDelta),插值方法,即返回参数from到to的插值,且返回值的最大角度不超过maxDegreesDelta。maxDegreesDelta是角度值,不是插值系数,当maxDegreesDelta < 0时,将进行逆向插值即从to到from的方向进行插值计算

Quaternion q1 = Quaternion.Euler(0,0,0);
Quaternion q2 = Quaternion.Euler(45, 44, 41);

m_speed += Time.deltaTime;
transform.rotation = Quaternion.RotateTowards(q1, q2, m_speed);

你可能感兴趣的:(Unity大杂烩,unity)