统一四元数,保持x和z旋转

时间:2018-05-30 17:28:50

标签: c# unity3d rotation quaternions

首先:这是我的代码:     使用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);

}
}

好的,这是我的代码。 Yrotation是我要“复制”的另一个对象的旋转。如果您需要更多细节,请询问。我想要实现的是将Q和z保留在Qrotation中。

1 个答案:

答案 0 :(得分:3)

尝试使用

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

而不只是为XZ

添加零
相关问题