四元数旋转

using UnityEngine;
using System.Collections;

public class SetFromToDirection_ts : MonoBehaviour
{

    public Transform A, B;
    float angle;
    Vector3 axis = Vector3.zero;
    float xSpeed = 0.0f, ySpeed = 0.0f, zSpeed = 0.0f;
    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        xSpeed += 0.5f * Time.deltaTime;
        ySpeed += 1.0f * Time.deltaTime;
        zSpeed += 2.5f * Time.deltaTime;
        //直接赋值
        A.eulerAngles = new Vector3(xSpeed, ySpeed, zSpeed);

        //创建实例
        Quaternion q=Quaternion.identity;
        q.eulerAngles= new Vector3(xSpeed, ySpeed, zSpeed);
        B.rotation = q;

        //获取A的rotation的旋转轴和角度
        A.rotation.ToAngleAxis(out angle, out axis);
        //设置B的rotation,使得B的rotation和A相同
         B.rotation = Quaternion.AngleAxis(angle, axis);
    }
}

猜你喜欢

转载自blog.csdn.net/lvcoc/article/details/85246616