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 :)
Here's the code:
void Update () {
if(Input.GetKey(KeyCode.A)){
transform.position += -transform.right * Speed * Time.deltaTime;
}else if (Input.GetKey(KeyCode.D)){
transform.position += transform.right * Speed * Time.deltaTime;
}
if(Input.GetKey(KeyCode.W)){
transform.position += transform.forward * Speed * Time.deltaTime;
}else if (Input.GetKey(KeyCode.S)){
transform.position += -transform.forward * Speed * Time.deltaTime;
}
}
I changed the transform.position += to ridgidbody.velocity = so that the player could easily collide with objects. Jumping is even worse though. The jump is extremely small and the fall is super slow. Still up for any ideas though.
Your answer
![](https://koobas.hobune.stream/wayback/20220612053320im_/https://answers.unity.com/themes/thub/images/avi.jpg)