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
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.
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)