Quaternion.LookRotation
2014-08-08 11:13
246 查看
此函数作用是生成一个四元数表示的三维朝向,然后可以直接把这个朝向赋给游戏对象来变更其朝向,也可以通过线性插值(Quaternion.Slerp 和 Quaternion.Lerp)来实现游戏对象从当前朝向转到这个新生成的朝向上来。很方便也很好玩的东西,可就是两个参数理解起来太让人头大了……
官网对此函数的参数和解释如下:Quaternion.LookRotation static function LookRotation (forward : Vector3, upwards : Vector3 = Vector3.up) :
QuaternionDescriptionCreates a rotation that looks along forward with the the head upwards along upwardsLogs an error if the forward direction is zero.
矢量减法,如下图。
如伪代码:
this.FightDir = Vector3.zero;
this.FightDir = AttackRole.transform.position - base.transform.position;
this.FightDir = new Vector3(this.FightDir.x, 0f, this.FightDir.z);
this.FightDir = this.FightDir.normalized;
if (this.FightDir != Vector3.zero)
{
base.transform.rotation = Quaternion.LookRotation(this.FightDir);
}
官网对此函数的参数和解释如下:Quaternion.LookRotation static function LookRotation (forward : Vector3, upwards : Vector3 = Vector3.up) :
QuaternionDescriptionCreates a rotation that looks along forward with the the head upwards along upwardsLogs an error if the forward direction is zero.
矢量减法,如下图。
如伪代码:
this.FightDir = Vector3.zero;
this.FightDir = AttackRole.transform.position - base.transform.position;
this.FightDir = new Vector3(this.FightDir.x, 0f, this.FightDir.z);
this.FightDir = this.FightDir.normalized;
if (this.FightDir != Vector3.zero)
{
base.transform.rotation = Quaternion.LookRotation(this.FightDir);
}
相关文章推荐
- Unity 利用Quaternion.LookRotation API 将旋转矩阵转换成四元数
- UnityEngine.Quaternion.LookRotation详解
- 面向组件编程之Unity 11.Quaternion.LookRotation 转自lijing_hi
- unity3d中的Quaternion.LookRotation
- Transfor.LookAt与Quaternion.LookRotation
- transform.LookAt与Quaternion.LookRotation
- UnityEngine.Quaternion.LookRotation详解
- unity3D 彻底搞懂 Quaternion LookRotation FromToRotation SetLookRotation方法
- Unity3D:详解注视旋转(Quaternion.LookRotation)
- [Unity 3D] Quaternion.LookRotation
- [Unity 3D] Quaternion.LookRotation
- unity3d Quaternion.LookRotation 控制车载机抢旋转
- Quaternion.LookRotation 注视旋转
- Quaternion.LookRotation
- 浅谈Unity中的rotation和Quaternion的乘法
- operator*(lhs:Quaternion,rhs:Quaternion)和operator*(rotation:Quaternion, point:Vector3)使用解析
- unity 关于Rotation和Quaternion的一些问题(欧拉角与四元数,lerp与slerp)
- Eigen库 EulerAngles <-->RotationMatrix<-->Quaterniond 转换方法 欧拉角<-->旋转矩阵<-->四元数
- Unity3D中Quaternion类SetLookRotation方法和LookRotation方法使用解析
- 浅谈Unity中的rotation和Quaternion的乘法