您的位置:首页 > 移动开发 > Unity3D

Unity3D Quaternion的一些记录

2014-03-19 10:07 316 查看
1、一个物体面向另一个物体

myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);

myTransform面向target。

或者:

transform.LookAt(target); 

都可以

2、
function ToAngleAxis (out angle : float, out axis :
Vector3) : void 

一个物体,沿着某一个轴axis的旋转角度

eg:

Quaternion pRotation = player.transform.localRotation;
float a = 0.0f;
Vector3 b = Vector3.up;
pRotation.ToAngleAxis(out a, out b);

float angle;
if (pRotation.y >= 0)
{
angle = a;
}
else
{
angle = 360 - a;
}
Debug.Log("angle = " + angle);
transform.localEulerAngles= new Vector3(0, 0, angle);

3、static function Angle (a : Quaternion, b : Quaternion) : float 
两个 物体之间的角度

4、function SetFromToRotation (fromDirection :
Vector3, toDirection : Vector3) : void 

从from到to旋转
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Quaternion