How to stop my character from jumping backward and not reducing speed.

Im doing a third person controller and I use the mouseorbit script from here. My problem is when I press “S” and my camera was camera X rotation is greater the 0, my character starts to jump backward and slightly slow when moving forward . How can I fix this? My movescript use Camera.main.transform.TransformDirection to rotate and move my character towards camera front direction. Here is my script

		if (input.x != 0f || input.y != 0f)
		{
			// rotate
			Vector3 targetDirection = new Vector3 (input.x, 0f, input.y);
			targetDirection = Camera.main.transform.TransformDirection (targetDirection);
			targetDirection.y = 0f;

			Quaternion targetRotation = Quaternion.LookRotation (targetDirection, Vector3.up);
			Quaternion newRotation = Quaternion.Slerp (transform.rotation, targetRotation, m_turnSmoothing * Time.deltaTime);
			transform.rotation = newRotation;

			// move
			Vector3 newMovement = new Vector3 (input.x, 0f, input.y);
			newMovement = Camera.main.transform.TransformDirection (newMovement);
			newMovement = newMovement.normalized * m_speed * Time.deltaTime;
			playerRigidbody.MovePosition (transform.position + newMovement);
		}

Your TransformDirection call will take the camera’s rotation into account, including pitch, which can mean that your “horizontal” movement now has a vertical component.

The simplest way to fix this is by manually removing that vertical component – in other words, just set Y to zero.

Vector3 newMovement = new Vector3 (input.x, 0f, input.y);
newMovement = Camera.main.transform.TransformDirection (newMovement);
newMovement.y = 0f; //no vertical movement!
newMovement = newMovement.normalized * m_speed * Time.deltaTime;

I was having a similar issue and it was due to the third person character got grounded by its grounded function. Lowering the grounded checkray distance while jumping fixed it for me.

I know this thread is ancient, I just stumbled across it trying to solve the exact same problem, and came out with a different solution.

Instead of tying the character backward movement direction to the direction of the camera, I tied the character’s movement direction to the character object itself by creating a variable for the target’s transform with:

public Transform target;

Then I dragged the character object to the target box in Unity, and after that I just changed the code for the letter “s” :

if (Input.GetKey(“s”))
{
rb.AddForce(-target.transform.forward * distance * Time.deltaTime);
}

(the variable “distance” is a variable I used to measure force)

I hope this helps someone out there.