Quaternion.LookRotation

来源:互联网 发布:淘宝网店数据分析 编辑:程序博客网 时间:2024/05/01 19:04

此函数作用是生成一个四元数表示的三维朝向,然后可以直接把这个朝向赋给游戏对象来变更其朝向,也可以通过线性插值(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);
                }


0 0
原创粉丝点击