# how to extract the Quaternion.Euler X of a transform.rotation (not the Quaternion X)?

I’ve got a camera rotating around an object (cf my other post Link of the post)
One of my problem is that I can’t extract the X angle then do my Y rotation them put back the X.

I set my Y rotation with a Quaternion.Euler. It seems (tell me if i’m wrong) that in the inspector the number in the rotation X is the Quaternion.Euler X.
If I print the transform.rotation.x and set transfrom.rotation = Quaternion.Euler(45,0,0);
In the inspector my number in the rotation x is ±45 and the number printed is ± 0.33.

I know now that a Quaternion is a Vector4 and the Euler is a Vector3.

So basicaly:

My Rotation need to be applyied only in Y nothing else should be modified.

• I want to extract the Quaternion.Euler.x of the transform.rotation of the current rotation to QuatEulX (for exple)

• Set a rotation and set the X of rotation with “rotation = Quaternion.Euler(QuatEulX,Time.time,0);”

Obviously transform.rotation.Euler.x or transform.rotation.Euler doesn’t exist or work…

Any ideas, I am completely wrong in my way of trying to do this ?

Vector3 eulerAngles = transform.eulerAngles;
eulerAngles.x = value;
transform.eulerAngles = eulerAngles;

Thanks a lot, I tried the eulerangles before but in a wrong way.

I modified a little bit my script an embed yours, and now the rotation starts in the exact position as it is at the moment, and only rotates around the Y axis.

Now I need to make my “wowcam” start from the point where the camera is when i’m clicking.

``````using UnityEngine;

using System.Collections;

public class RotateCam : MonoBehaviour

{

//--------------------------------------------------

// Script By Boris Baghdikian b.baghdikian@gmail.com

//--------------------------------------------------

//-------------------------------Déclaration des Variables-----------------------------

//-------------Rotation Variables---------------------

//Rotation Speed

public float xSpeed = 200.0f;

public float ySpeed = 200.0f;

public float SpeedCoef = 0.02f;

// Y Axis Limits

public float yMinLimit = -80.0f;

public float yMaxLimit = 80.0f;

//Damping

public float RotDamp = 5.0f;

//AmtToRotate in degrees

public float xDeg = 0.0f;

private float yDeg = 0.0f;

private float y;

//Rotation from current to desired

public static Quaternion currentRotation;

public Quaternion desiredRotation;

public Quaternion rotation;

//---------Position Variables--------------------------

// Target

public Transform target;

public Vector3 targetOffset;

// Distances and positions

public float distance = 5.0f;

public float maxDistance = 20.0f;

public float minDistance = 0.6f;

private float currentDistance;

public static float desiredDistance;

private Vector3 position;

//Zoom parameters

public int zoomRate = 150;

public int zoomRateRMB = 550;

public float zoomDamp = 5.0f;

//interrupteur GUI

public static bool interrupteur = true;

//Sensibility Zooms

public int RClicSensibility;

public int MidSensibility;

public Transform thisTransform;

//public Vector3 startPos;

//public Vector3 endPos;

public float time;

public float i;

public float rate;

public static bool home;

public static float x;

public bool Starter = true;

private float StartTime;

private bool Rot = false;

public float Speed;

public static float Speed2;

public float StartingTime;

private bool Reset = false;

private float Rx;

private float Rz;

//-------------------------------   START   -------------------------------

// Use this for initialization

void Start()

{

//-------------Set initial Rotation--------------------

rotation = transform.rotation;

currentRotation = transform.rotation;

desiredRotation = transform.rotation;

xDeg = Vector3.Angle(Vector3.right, transform.right);

yDeg = Vector3.Angle(Vector3.up, transform.up);

//-----------Set initial Position----------------------

distance = Vector3.Distance(transform.position, target.position);

currentDistance = distance;

desiredDistance = distance;

position = transform.position;

Speed2 = Speed;

}

private bool ApproxEquals(float a, float b)

{

return (a <= b + 0.01  a >= b - 0.01);

}

//-------------------------------   UPDATE   -------------------------------

// Update is called once per frame

void Update()

{

if (interrupteur == true)

{

//--------------Rotation--------------------

//Check if the mouse button is on

//Set the AmtToRotate

if (Input.GetMouseButton(0))

{

if(Reset == true)

{

currentRotation = transform.rotation;

desiredRotation = transform.rotation;

xDeg = desiredRotation.y;

yDeg = desiredRotation.x;

Reset = false;

}

//Set the AmtToRotate

xDeg += Input.GetAxis("Mouse X") * xSpeed * SpeedCoef;

yDeg -= Input.GetAxis("Mouse Y") * ySpeed * SpeedCoef;

// Make sure that the yDeg is still in the Y limits

yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);

//Use the AmtToRotate to rotate the camera

desiredRotation = Quaternion.Euler(yDeg, xDeg, 0);

currentRotation = transform.rotation;

rotation = Quaternion.Slerp(currentRotation, desiredRotation, Time.deltaTime * RotDamp);

transform.rotation = rotation;

}

if (!Input.GetMouseButton(0))

{

currentRotation = transform.rotation;

rotation = Quaternion.Slerp(currentRotation, desiredRotation, Time.deltaTime * RotDamp);

transform.rotation = rotation;

}

//---------------Position------------------

//Set the AmtToMove

desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs(desiredDistance) * MidSensibility;

if (Input.GetMouseButton(1))

{

desiredDistance -= Input.GetAxis("Mouse Y") * RClicSensibility;

}

//Clamp the zoom min/max

desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance);

currentDistance = Mathf.Lerp(currentDistance, desiredDistance, Time.deltaTime * zoomDamp);

// New position

position = target.position - (rotation * Vector3.forward * currentDistance + targetOffset);

transform.position = position;

}

}

private static float ClampAngle(float angle, float min, float max)

{

if (angle < -360)

angle += 360;

if (angle > 360)

angle -= 360;

return Mathf.Clamp(angle, min, max);

}

}
``````

thanks again, one last step and my system is done !! woot woooooot !