Add Gravity to Player
Physics Based Character Controller part 2
In this article we will add gravity to our player controller.
When player is NOT touching the ground we apply gravity. This is a float number we set at the top of our script. We can simply subtract gravity from the y value of our velocity.
Vector3 direction = new Vector3(Input.GetAxis(“Horizontal”), 0);
Vector3 velocity = direction * _speed;
if (_controller.isGrounded == true)
velocity.y -= _gravity;
_controller.Move(velocity * Time.deltaTime);