Rotate Player to camera direction (and not the other way around)

Trying to figure out how to turn my player to face the direction of the camera as opposed to the other way around. basically I just want to set it up so when I hit the forward key the player rotates to the direction of the camera then moves forward. This is what I’ve got so far:

cameraDirection = cameraPlayer.transform.forward;

currentMovement = new Vector3(0, currentMovement.y, Input.GetAxis("Vertical") * moveSpeed);

controller.Move(currentMovement * Time.deltaTime);

this is all in the Update

I’m assuming I will need to include a line like:

if (Input.GetButtonDown("Forward"))

so I know when I’m updating the character movement, but I’m having trouble figuring out how to add a line that changes the rotation of the player to the rotation of the camera.

I’m having a lot of trouble figuring out how to rotate the player. It seems the camera direction is not a typical direction that I can just rotate to like its another object. can anyone offer any advise?

Alright so I found this little gem:

transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, Camera.main.transform.localEulerAngles.y, transform.localEulerAngles.z);

so now my player rotates to the direction I want, but the player still only moves in one direction (not the direction I’m facing) any ideas why my forward direction isn’t updating?

3 Likes

This answer solved my problem completely!! Thanks :slight_smile:

Try this one :

 transform.Translate(Vector3.forward.normalized*speed);
transform.eulerAngles = new Vector3(transform.eulerAngles.x, Camera.main.transform.eulerAngles.y, transform.eulerAngles.z);