Quaternion:通过API对Quaternion(四元数)类中的方法属性进行测试(一)

时间:2021-12-11 07:28:30

返回一个四元数,返回From与To的差值,并以Time.detaltime*speed变化着

Quaternion.Lerp(From.rotation,To.Rotation,Time.detaltime*speed);

例如 以下代码中C,D将以A.Rotation为起始点,以B.rotation为结束点以total为速度进行变化

using UnityEngine; using System.Collections; pubilc class Eaxmble:MonoBehaviour { public Transform A,B,C,D; float speed=0.2f; float total=0.0f; void start() { } void Update() { total+=Time.deltaTime*speed; if(total>=1.0f) total=1.0f; C.rotation=Quaternion.Lerp(A.rotation,B.rotation,total); D.rotation=Quaternion.Lerp(A.rotation,B.rotation,total); } }

Lerp

2.LookRotation方法

a:Quaternion.LookRotation(Vector3.forword);

b:Quaternion.LookRotation(Vector3.forword,Vector.up);

个人看法:对这个方法不是很理解,不过知道它的一些用法,

Vector3.forword应该是transform.position-target.position这样就可以实现gameObject的Z轴始终指向target.posotion

a方法是按照Vector3.up作为旋转轴

b方法的旋转轴可以通过定义Vector.up来实现是围绕自身的transform.up旋转还是围绕Vector.up,或者是其他

以下是测试用的代码

LookPosition

Quaternion:通过API对Quaternion(四元数)类中的方法属性进行测试(一)