How do you maintain gravity using transform.forward and transform.right?

I’m making my own first-person game and I have this problem where whenever I move after jumping, the player slowly falls to the ground. I know that when I use transform.forward the y values of the player are being set to 0 and the downward force is basically being reset, that’s why it falls slowly. I just need help finding a way to maintain the gravity of the player.

I know I can use a character controller and all that, but I want to learn how to do it this way. I’m willing to change the code around, I just don’t want to use a controller. Thanks :slight_smile:

Here’s the code:

	void Update () {
			transform.position += -transform.right * Speed * Time.deltaTime;
		}else if (Input.GetKey(KeyCode.D)){
			transform.position += transform.right * Speed * Time.deltaTime;
			transform.position += transform.forward * Speed * Time.deltaTime;
		}else if (Input.GetKey(KeyCode.S)){
			transform.position += -transform.forward * Speed * Time.deltaTime;

Just add your own gravity in the update section and check whether the player is grounded or not. If the player is grounded just set the “player_gravity to 0” and if he isnt grounded then set the gravity force to your concern with rb.AddForce(Physics.gravity * player_gravity, ForceMode.Force); worked for me :wink:

Edit: too late of a answer I know I just saw this post hope anyone who is trying to find the same problems finds this answer