unity quaternion,保持x和z旋转不变
Unity quaternion, leaving the x and z rotations as they are
所以开始吧:这是我的代码:
使用 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 是我想要 "copy" 的另一个对象的旋转。如果您需要更多详细信息,请询问。我想要实现的是不指定 Qrotation 中的 x 和 z。
尝试使用
Qrotation = Quaternion.Euler(transform.eulerAngles.x, Rotationthingy, transform.eulerAngles.z);
而不是只为 X
和 Z
置零
所以开始吧:这是我的代码: 使用 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 是我想要 "copy" 的另一个对象的旋转。如果您需要更多详细信息,请询问。我想要实现的是不指定 Qrotation 中的 x 和 z。
尝试使用
Qrotation = Quaternion.Euler(transform.eulerAngles.x, Rotationthingy, transform.eulerAngles.z);
而不是只为 X
和 Z