Stop character controller from detaching from ramp

I have the following line of code:
velocity -= Vector3.Dot(collision.normal, velocity) * collision.normal);

This line of code runs whenever OnControllerColliderHit() is called. Essentially, this is just Newton’s Third Law for character controllers. The purpose of this is to slow the player down when they bump into walls, for realism. I do not think this is the root of the problem, but it might be important to consider when fixing.
_
I do not know why, but when going UP ramps, after letting go of movement keys the player’s velocity.y increases.
In the following image, the player is walking up a ramp at a constant rate: 151761-goingupslope.png
In the next image, the player is no longer holding down the forward key/is not trying to move anywhere. As soon as the player lets go of w, a, s, and d, the player’s vertical velocity changes to a positive number instead of the player just staying in place on the ramp:
151762-goinguponslope.png
My question is how do I stop the player from moving upwards when they shouldn’t be or improve the script to stop this from happening? I need the player to slow down against walls appropriately, but I also need this bug not to occur. Other important variables include: The character controller’s step offset is 0, skin width is 0.01, and slope limit is 1. I replicate gravity by applying a constant downward force of 20 per second. When I remove the velocity change upon collision, this still happens. What is causing the player to move upwards when moving against ramps/slopes?

Figured it out. The line of code I had was fine, and appropriately applies force in the necessary direction in order to replicate newton’s third law. The issue was that my gravity was only being applied in certain conditions, preventing the player from losing vertical speed in said conditions, and thus creating the error. I moved the gravity to fixed update and all is well.