- Home /
how do i change the direction of my player using the camera's Y rotation
if the camera's Y rotation = 0 then i want my player to move in the +Z direction, so how do i do this
its a 3-D game, I'm using Rigid Body to move my player, transform to rotate my camera. i can change the movement / rotation if needed to Rigid Body or Transform.
by the way i'm using c#.
Comment
Answer by Llama_w_2Ls · Jul 22, 2020 at 05:38 PM
bean.transform.rotation = Quaternion.Euler(0, camera.transform.eulerAngles.y, 0);
//locks the y-rotation of the GameObject 'bean' to the camera's y rotation
transform.position = new Vector3(bean.transform.position.x, camera.transform.position.y, bean.transform.position.z);
//sets the camera's x and z position to the bean's x and z position
@Jonah-H This code snippet allows the camera to follow the player (but im guessing youve already done that part) and allows the player's y rotation to lock onto the camera's y rotation. Hope it helps.