Quaternion

xiaoxiao2021-02-28  140

结构体Quaternion 简单的说几个常见的用法:

Quaternion q = Quaternion.identity;// 无旋转 print(gameObject.transform.eulerAngles);// 输出的是Vector 3 也就是Transform组件的rotation print(gameObject.transform.rotation);// 输出的是四元数 // 若想直接让他绕X轴旋转90度 gameObject.transform.eulerAngles = new Vector3(90, 0, 0); gameObject.transform.rotation = new Quaternion(0.7f, 0, 0, 0.7f); // Quaternion.Euler 将欧拉角转成四元数 gameObject.transform.rotation = Quaternion.Euler(new Vector3(90, 0, 0)); // 将四元数转成欧拉角 gameObject.transform.eulerAngles = (new Quaternion(0.7f, 0, 0, 0.7f)).eulerAngles; // 控制玩家望向敌人 Vector3 dir = enemy.transform.position - player.transform.position; dir.y = 0;// 忽略高度差 player.transform.rotation = Quaternion.LookRotation(dir); // 给定一个速度转向敌人 Slerp优于Lerp (经测试虽然没多大区别) Quaternion target = Quaternion.LookRotation(dir); player.transform.rotation = Quaternion.Slerp(player.transform.rotation, target, Time.deltaTime);
转载请注明原文地址: https://www.6miu.com/read-58880.html

最新回复(0)