How can I rotate my player without affecting movement direction?

Hi there,

I’m using the script below to move and rotate my player object, the player only moves in one direction which is backwards along the X axis and rotates to look at the mouse position.

I need to use Rigidbody movement as the player needs to be affected by gravity at certain stages. The problem I’m having is that when I try to rotate the player, the direction at which he is moving also changes(so he can potentially go backwards).

So, How can I move my player constantly on the X axis and rotate him without changing the direction he is moving?

Here is what I am using so far

		Vector3 MouseWorldPosition = MainCamera.GetComponent<Camera> ().ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 50));
		transform.LookAt (MouseWorldPosition);
		transform.rotation = Quaternion.Euler (new Vector3 (0, transform.rotation.eulerAngles.y, 0));

		//Moves Player
		rb.MovePosition(transform.localPosition += -transform.forward * Time.deltaTime);

Also, currently for this to work I have to keep my rigidbody as kinematic or else the player goes flying!, why is this and can I change it?


//Moves Player

         rb.MovePosition(transform.localPosition += -transform.forward * Time.deltaTime);

This line is moving the character backwards on their local Z axis.

//Moves Player
             rb.MovePosition(transform.localPosition += -Vector3.right * Time.deltaTime);

Try this instead. The character moves on the global X axis, rather than local Z, by changing transform.forward into Vector3.right.