代码之家  ›  专栏  ›  技术社区  ›  ThePurpleArcher

四元数,保持x和z旋转不变

  •  1
  • ThePurpleArcher  · 技术社区  · 7 年前

    首先:这是我的代码: 使用unityengine;

    public class LockRotation : MonoBehaviour
    {
    Rigidbody m_Rigidbody;
    public Transform Yrotation;
    public float Rotationthingy;
    public Quaternion Qrotation = Quaternion.Euler(0, 0, 0);
    
    void Start()
    {
        m_Rigidbody = GetComponent<Rigidbody>();
    
    }
    void FixedUpdate()
    {
        Rotationthingy = Yrotation.rotation.eulerAngles.y;
    
        Qrotation = Quaternion.Euler(0, Rotationthingy, 0);
        m_Rigidbody.MoveRotation(Qrotation);
    
    }
    }
    

    好的,这是我的代码。旋转是另一个对象的旋转,我想“复制”。如果你需要更多的细节,尽管问。我想得到的是,让x和z在qrotation中保持未明。

    1 回复  |  直到 7 年前
        1
  •  3
  •   Daxtron2 programmergirl90    7 年前

    尝试使用

    Qrotation = Quaternion.Euler(transform.eulerAngles.x, Rotationthingy, transform.eulerAngles.z);
    

    而不是只为 X Z