因此,开始:这是我的代码:
    使用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是我要“复制”的另一个对象的旋转。如果您需要更多详细信息,请询问。我想实现的是未指定Qrotation中的x和z。

最佳答案

尝试使用

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


而不只是将XZ置于零

关于c# - Unity四元数,保持x和z旋转不变,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50610448/

10-09 03:11