This is part 2 of Implementing a Physics based character controller. In the last article, I was able to get the Player to move left and right albeit slowly. It had direction and now we can incorporate speed:
All that needs to be done to create velocity is to multiply direction with speed. Also to make it framerate independent which means that the behavior should be consistent in varying hardware, you need to multiply it with Time.deltaTime.
As for gravity, we can determine if the object is grounded with CharacterController.isGrounded and if it’s not, add a rate of downward change by deducting value on the y-Axis of the direction.
For now, I set _speed to 5f and _gravity to 1f so the player moves at 5 units per second but falls 1 unit per second.