Prevent Rigidbody from Shooting Off Slopes

I’ve seen a couple posts about this but I don’t think I can implement them into my movement system.

Does anyone have a good solution for this?

Here is how I’m moving currently, it keeps the character on the ground when walking up/down slopes, but sometimes I still shoot off at the crest of slopes, since I’m adding force to the X-Axis.

Code (CSharp):

        bool downHill = (straffe >= 0 && slopeHit.normal.x >= 0 || straffe <= 0 && slopeHit.normal.x <= 0); //Checking the ground to see if we're going uphill or downhill.
        float f = straffe;

         f = downHill ? f : f / 1.5f;

        Vector3 targetVel = new Vector3(f, 0, 0);
        Vector3 slopeMove = Vector3.ProjectOnPlane(targetVel, slopeHit.normal);
        Vector3 velChange = slopeMove - rB.velocity;

        rB.AddForce(velChange, ForceMode.VelocityChange);

If there are no good physics solutions to this problem than I think clamping the player to the ground would be good as well… not quite sure how to do that though.

Any thoughts? Thanks!

Hey!
I am not quite sure what you mean by shooting off slopes?
Could you provide with an example of what is happening?