Take the rotation of one object and import it into another on a single axis.

I would like to take the Y rotation of one object and paste it into another, but I’m having a hard time understanding how Unity handles rotations. I have read the manual on Quaternions and I’m not sure how I should write my C# code.

Taking the position of one object using Vertex3 is easy enough but I’m having a hard time understanding if I have to use euler angles. I understand a single rotation axis can not be represented in euler angles since quaternions have to be represented with XYZW at all times. I don’t want to know the actual angle. I just want to copy it. I don’t care about the math that Unity does behind the scenes.

I’m essentially unsure of the exact line of code to use.

if you want the global rotation you could write it like either one of these lines:

transform.Rotate(0,transform2.eulerAngles.y-transform.eulerAngles.y,0,Space.World);
transform.eulerAngles = new Vector3(transform.eulerAngles.x,transform2.eulerAngles.y,transform.eulerAngles.z);

with unitys transform functions there is usually no need to edit a quaternion directly.

Thanks a lot. I don’t know why I had so much trouble with this.