How can I make the player look at the camera while rotating?

I made a camera script for my 3d platform character but having some slight issue. When ever I move my player with the rigidbody, I can move just fine. But when ever I rotate my camera left or right, and while pushing the key W (as in going forward) the player is not going with the camera rotation. Instead its going one direction and that’s it. How can this be solved?

Possibly, by setting the Player’s rotation to the camera’s horizontal rotation whenever W or S is pressed. I can try write the code if you want.

If it’s not too much trouble
But when the camera rotates, the player should stand still while I push a key,he rotates

I came across the same problem a few weeks ago when starting to use rigidbody for my character controller script. I should test before posting but if i remember correctly, the way of solving this issue. Its by transforming the direction before apply any movement or force to the rigidbody. Something like this.

void FixedUpdate()
		moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
		moveDirection = transform.TransformDirection(moveDirection);

		_body.MovePosition(_body.position + moveDirection * Speed * Time.fixedDeltaTime);

I have setup a private vector3 on the initialization of the variables, then i read the inputs like shown in the code sample. The second line is what you should be testing on, becouse that transform the direction of the vector3 called moveDirection. moveDirection as it is right there, is “drawing” the shape of a + on the world matrix, so there is no relative direction to the camera rotation. By setting the moveDirection vector to be relative of the transform then the axis will be corrected to be facing the direction of the transform you are rotating with the camera. When you are applying directions for an object to move along they use world direction by default, so in order to change that you have to use that “transform.TransformDirection(vector3)” line.

I hope it helps, at least thats what solved my own problem a few weeks ago.