Quaternion.LookRotation

本文详细介绍了Unity中Quaternion.LookRotation函数的使用方法及其参数意义,该函数用于生成表示三维朝向的四元数,方便游戏对象朝向的快速设置与平滑过渡。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值