unity 设置player Y-rotation等于camera Y-rotation
Unity set player Y-rotation equal to that of the camera Y-rotaion
我需要直接设置播放器的 Y-Rotation 等于 Camera.main
Y-Rotation 我已经搜索了很多但找不到答案。
我知道这很简单,但我做不到。
编辑:我试过这段代码
transform.rotation = Quaternion.Euler(Camera.main.transform.eulerAngles);
但是它设置了物体的整个旋转等于相机X,Y,Z的旋转但是我想要的是只设置y rotation.Thanks求助
编辑2:
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.
应该可行:
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, Camera.main.transform.eulerAngles.y, transform.rotation.eulerAngles.z);
我需要直接设置播放器的 Y-Rotation 等于 Camera.main
Y-Rotation 我已经搜索了很多但找不到答案。
我知道这很简单,但我做不到。
编辑:我试过这段代码
transform.rotation = Quaternion.Euler(Camera.main.transform.eulerAngles);
但是它设置了物体的整个旋转等于相机X,Y,Z的旋转但是我想要的是只设置y rotation.Thanks求助
编辑2:
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.
应该可行:
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, Camera.main.transform.eulerAngles.y, transform.rotation.eulerAngles.z);