Legendary Falling trough floor

So i have a c# script for crouching,And as hard as i try to find solution to not fall trough floor i can’t.So can someone help me ?

C#

public class Crouch : MonoBehaviour
{

	public AnimationCurve crchHeightAnimation = new AnimationCurve(new Keyframe[] 
											{ new Keyframe(0f, 0f), new Keyframe(0.5f, 0.3f), new Keyframe(1f, 1f) });

	public CharacterMotor CharMotor;
	public CharacterController CharCont;
	private Transform _transform;
	public float crouchSpeed = 1; 
	public float crouchHeight = 1f; 
	private float crouchPhase;
	private float initHeight;

	void Start()
	{
		_transform = transform;
		initHeight = CharCont.height;
	}

	void FixedUpdate()
	{
		float crouchHeightOld01 = crchHeightAnimation.Evaluate(crouchPhase);
		crouchPhase = Mathf.MoveTowards(crouchPhase, Input.GetKey(KeyCode.C) ? 1f : 0f, Time.fixedDeltaTime);
		float crouchHeightNew01 = crchHeightAnimation.Evaluate(crouchPhase);
		


		CharCont.height = initHeight - crouchHeightNew01 * crouchHeight;
		CharCont.center = Vector3.Lerp(Vector3.zero, Vector3.up * crouchHeight * 0.5f, crouchHeight);
		transform.position -= Vector3.up * (crouchHeightNew01 - crouchHeightOld01) * crouchHeight;
	}
}

Any tips or help?
Thank you

in your crouch function you are messing with the collider, and yes it will fall thourgh the ground because when the collider is being scaled and or move the unity turns it off, now for crouching what some people do is to turn of gravity first then do the collider stuff then apply the motion needed and to get back up you might want to make it so you put is up.

You could try having two colliders. When running normally, turn off the crouch one. When they crouch, turn on the crouch one and turn off the normal one.