Essentially this is what I am doing
1.Casting a Ray down to the ground from player.
2.float distance = Vector3.Distance(transform.position, hit.point);
When it executes, before I input anything the values seem reasonable. Once I input movement the values vary sporadically up to 9.0 when it shouldnt exceed more than 2 at most.
I have encountered the problem but have no solution. Essentially the character controller down force is interfering with the Distance values because there is a verticalVelocity += downforce value; or to be more specific movement.y -= speed.
Before you say, duh make sure your player is grounded and dont add force when it is. THAT was one problem to begin with. The character controller isGrounded check returns true/false several times per second if there is now downforce thus immediately causing problems with jump if you try jumping while isGrounded = true. To add to this pain, if youre on a slope and moving down, the character controller bounces downward causing even more sporadic checks of the is grounded bool. So I have fixed all of these pains by default by adding constant forces to Y value to ensure I am grounded at ALL times when my feet are planted. By default, try it, Debug.Log a character controller’s isGrounded (CharacterController.isGrounded) bool without force. It will consistently return true and false. I cant seem to find a solution because at no point can I turn those forces off or my controller will not be responsive. All is grounded check return perfectly fine as is with constant forces. I also print(myposition + hit.point) and they both are the expected static values even while I move. So why cant vector3.Distance keep track of that??? Anyways I will post my code and hopefully someone will have luck.
Lastly you may ask, why do I need this, 90% of the controller is functional, especially for what I specifically need. Slopes work fine say up to 80 degrees. After that, I have several issues where too steep is too much and the raycast doesnt pick up the floor and I can climb steep slopes with no sliding. So i want to check that raycast distance. If the control isGrounded and the distance is great, then I am floating on a steep slope and I use the OnControllerColliderHit to solve that. By default OnControllerColloderHit is terrible with smaller slopes, but with steep it work great so I want to use a combination of the two. Thank you.