0

I need to set directly the Y-Rotation of the player to be equal to the Camera.main Y-Rotation I have searched a lot but can't find the answer.

I know it is simple but I can't manage it.

Edit: I tried this code

transform.rotation = Quaternion.Euler(Camera.main.transform.eulerAngles);

But it set the rotation of the whole rotation of the object equal to the rotation of the camera X,Y,and Z but what I want is to set only the y rotation.Thanks for help.

Edit2:PlayerImage

I forgot to say whay I am using this in I am making a VR Game so when the player rotates his head the camera rotates successfully.

Note: Why I want to do that? because when my player has to move forward it has to have the same y rotation of the camera.

Programmer
  • 121,791
  • 22
  • 236
  • 328
Joe
  • 879
  • 3
  • 14
  • 37
  • Can you provide a diagram, or some screenshots of what you're trying to achieve? It's possible that setting the rotation directly may not actually be the best/simplest course of action here. – Serlite Jul 31 '18 at 18:36
  • @Serlite I have edited question check it please. – Joe Jul 31 '18 at 18:44

1 Answers1

4

That should work:

transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, Camera.main.transform.eulerAngles.y, transform.rotation.eulerAngles.z);