Match Y axis rotation.

Hi,

I’m having an issue with matching rotations. I have a camera which rotates on all axes. What I’m trying to do is match the Y axis rotation of the camera to another game object.

My current solution:

private GameObject playerbox;

private Quaternion referenceRotation = Quaternion.identity;
private GameObject playerbox;

void Start () 
{AttachGyro();
	playerbox = GameObject.Find("Playerbox");
}

void Update(){

	playerbox.transform.Rotate(0,referenceRotation.eulerAngles.y, 0);
	Debug.Log (referenceRotation.eulerAngles.y);

However this doesnt seem to work at all. It bugs out the camera and the “Playerbox” object doesn’t seem to change rotation at all (or really swiftly).

Any ideas would be appreciated!

You’re trying to rotate by the amount, not move to the point. Try this

Transform.eulerangles = vector3(transform.eulerangles.x, reference.eulerangles.y, transform.eulerangles.z);