- Home /
Synchronising the rotation around Y axis of two objects
Hey all,
I have a player and a 3rd person view camera which is controllable by the mouse. I now want to be able to set the rotation of the player around the Y axis equal to the rotation of the camera around the Y axis. I tried gameObject.transform.rotation.y = GameObject.Find("Main Camera").transform.rotation.y;
. This makes it almost behave as I want it except it only works for 180 degrees. The other 180 degrees the character turns around in the opposite direction.
Does anyone know how I can do this?
It's weird... maybe you could try to put it into Camera's script and look for variable that counts y rotation, maybe it could be negative or... i don't know...
I didn't use the .eulerAngles.y but just the .y, so it's solved now :)
Answer by MikeNewall · May 24, 2013 at 07:54 PM
Try this:
float camY = Camera.mainCamera.transform.eulerAngles.y;
transform.eulerAngles = new Vector3(transform.eulerAngles.x,camY, transform.eulerAngles.z);
I edited my answer to use transform.eulerangles there was no need to convert it to a quaternion :-)
Your answer
![](https://koobas.hobune.stream/wayback/20220613102811im_/https://answers.unity.com/themes/thub/images/avi.jpg)