首页 > 代码库 > Quaternion:通过API对Quaternion(四元数)类中的方法属性进行测试(一)
Quaternion:通过API对Quaternion(四元数)类中的方法属性进行测试(一)
1.差值方法Lerp
返回一个四元数,返回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); } }
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(四元数)类中的方法属性进行测试(一)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。