How to get my sliding to work?

I made a character controller and my crouch works but when i use basically the same code tweaked a little for sliding it doesn’t work.

this is what my crouch void looks like and it works

private void CrouchPlayer()
{
if (Input.GetKey(KeyCode.LeftControl) && moveSpeed < minimumSlSpeed)
{
playerOHeight.transform.localScale = new Vector3(1, 1f, 1);
rb.mass = 20;
if (crouchDeclut == 0)
{ camHold.transform.position = new Vector3(camHold.transform.position.x, camHold.transform.position.y - 1, camHold.transform.position.z); crouchDeclut += 1; }
}
else
{
playerOHeight.transform.localScale = new Vector3(1, 1.5f, 1);
rb.mass = 10;
if (crouchDeclut == 1)
{ camHold.transform.position = new Vector3(camHold.transform.position.x, camHold.transform.position.y + 1, camHold.transform.position.z); crouchDeclut -= 1; }
}
}

this is what my slide looks like and it doesn’t work

private void SlidePlayer()
{
if(Input.GetKey(KeyCode.LeftControl) && moveSpeed > minimumSlSpeed)
{
playerOHeight.transform.localScale = new Vector3(1, 1f, 1);
if (crouchDeclut == 0)
{ camHold.transform.position = new Vector3(camHold.transform.position.x, camHold.transform.position.y - 1, camHold.transform.position.z); crouchDeclut += 1; }
rb.drag = 0.8f;
rb.mass = 5;
Debug.Log(“Working”);
}
else
{
playerOHeight.transform.localScale = new Vector3(1, 1.5f, 1);
rb.mass = 10;
rb.drag = 5.5f;
if (crouchDeclut == 1)
{ camHold.transform.position = new Vector3(camHold.transform.position.x, camHold.transform.position.y + 1, camHold.transform.position.z); crouchDeclut -= 1; }
}

}

Hard to see and help. You could put a larger part of your code into ChatGPT and ask.
Some remarks

  1. you check for moveSpeed < and > but not <= or or >=. Is it a float or an int, what if it’s equal?
  2. You implement logic and values in the same function. Consider working with a state (enum for example) and depending on the state, in one method, set values for mass and drag. Make the if-statements dependent on the state.
  3. if courchDeclut == 0 seems like a status check. So work with an enum to indicate the crouchStatusses.
  4. If you can crouch & slide at the same time, split it into a state and a movement or an event.

Hope it helps.

You can look at how this FPS controller does it:

That one has run, walk, jump, slide, crouch… it’s crazy-nutty!!

^ ^ ^ Not a useful description… but it just sounds like you wrote a bug… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

did debugging and got it working