Falling through floor when resetting collider

Hey everyone.

So, I have successfully implemented a slide animation with my character, but I am running into a problem where the player falls through the floor whenever a slide takes place.

I have realized that this is because I am re-sizing the players box collider (to make it more narrow, so that the player can slide under things), but when the player stops sliding (aka the slide button is released), the box collider goes back to the normal size, and since the player is in a sliding position, the bounds of the original box collider are beneath the floor, so the player falls through it.

I have tried messing with different centering and sizes for the box collider, but nothing seems to work.

Does anyone have any advice for something like this? I would really like to get these slides working.

if (Input.GetKeyDown (KeyCode.LeftControl))
            {
                sliding = true;//Set sliding bool in code to true
                animator.SetBool ("Sliding", true);//Set Sliding bool (in Unity) to true
                targetSpeed = 0;

                playerPhysics.SetCollider (new Vector3 (0.38f, 0.64f, 1.17f), new Vector3 (-0.05f, .30f, -0.16f));//Set the size of our collider box when the player is sliding (size, center)
            }

The attached code is the code for when sliding starts right?
What is the code for when sliding stops?

You could give your character two colliders - one for the upper half, and one for the lower, and then deactivate the one for the upper half when you slide.

Resizing colliders at runtime while that collider is colliding with things is generally a bad idea. If you insist on doing it, try to ensure that the collider’s bottom never changes position.

Simply lift the collider up…

Sorry, I should have included that.

This is what I am doing when sliding stops (when the speed becomes less then a certain amount)

if (sliding)
            {
                if (Mathf.Abs (currentSpeed) < .50f)
                {
                    sliding = false;//Set sliding bool in code to false
                    animator.SetBool ("Sliding", false);//Set Sliding bool (in Unity) to false

                    playerPhysics.ResetCollider ();//Calls the reset collider method to set the collision box to the original size
                }
            }

Thank you for the response. That was the first thing I tried, however, it was unsuccessful. Shifting the collider up causes the player to sink partially below the ground level, and then once the collider is reset to the original size, the player falls through.

Thank you for the response. How would I go about disabling one of the two colliders if I wanted to try it this way?

Update: Hey everyone, thank you all again for the responses. I have got this working now.

For some reason, using the Box Collider editing tool to get the exact sizes of the “sliding” box collider worked (even though my other dimensions were only thousandths of a unit off from the new ones), and my player is now able to slide under obstacles.

Thank you all again!