ThePurpleArcher
ThePurpleArcher

Reputation: 67

Unity quaternion, leaving the x and z rotations as they are

So to start off: Here's my code: using 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);

}
}

Okay, so this is my code. the Yrotation is the rotation of another object which I want to "copy". If you need any more details, just ask. And the thing I want to achive is to leave the x and z in Qrotation unspecified.

Upvotes: 2

Views: 336

Answers (1)

Daxtron2
Daxtron2

Reputation: 1309

Try using

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

instead of just putting zeroes for X and Z

Upvotes: 4

Related Questions