Strange falling through world when crouching

Hi, Ive made a crouch script and when i do, it works great… BUT, when I look up or down and then crouch i fall through the world. It uses the standard Unity FPS controller, ive just added the crouch script to it…

Heres the script:

	public bool isCrouching;
	
	public float crouchHeight;
	public float standardHeight;
	public CharacterController controller;
	public GameObject mainCam;
	public GameObject gameObj; 
	public	Vector3 startPos;
	public float length;
	
	public float camTest;
	
	public float crouchCamHeight;
	public float standardCamHeight;
	public float crouchDrop= -0.25f;


	void Start () {
		
	controller = GetComponent<CharacterController>();
	mainCam = GameObject.FindWithTag("CamB");
	gameObj = GameObject.Find("Robot_B(Clone)");
	
	
	standardHeight = 1.7f;
	crouchHeight = 1.1f;
		
	standardCamHeight = 1.0f;
	crouchCamHeight = -0.3f;
	}
	

	void Update () {
	if (Input.GetButtonDown("Crouch")) {
		if (isCrouching) {
				UnCrouch ();
		} 
		else {
			Crouch ();

			}
		}
	}
	
	void UnCrouch () {	
		if (networkView.isMine) {
		controller = GetComponent<CharacterController>();
		mainCam.transform.localPosition = new Vector3(0,standardCamHeight, 0.5f);
		controller.center = new Vector3(0,0,0);
		controller.height = standardHeight;
		GameObject RobBCrouch = GameObject.Find("ROBB");
		ROBOT_B_ANIMATE crouchComp = RobBCrouch.GetComponent<ROBOT_B_ANIMATE>();
		crouchComp.UnCrouch();
		isCrouching = false;
		}
	}
	
	void Crouch () {
		if (networkView.isMine) {
		controller = GetComponent<CharacterController>();
		mainCam.transform.localPosition = new Vector3(0,crouchCamHeight, 0.5f);
		controller.center = new Vector3 ( 0, crouchDrop, 0);
		controller.height = crouchHeight;
		GameObject RobBCrouch = GameObject.Find("ROBB");
		ROBOT_B_ANIMATE crouchComp = RobBCrouch.GetComponent<ROBOT_B_ANIMATE>();
		crouchComp.Crouch();
		isCrouching = true;
		}
	}

ignore the networking code.

My guess is that the first person camera controller uses the current camera location to decide the player location, so when you lower the camera by crouching your player is lowered as well and falls through the ground.

Maybe you could try thickening the ground beneath you to stop yourself from falling though, or force the FPS controller to always use the main camera.

You also seem to be changing the position of the controller. Try instead changing the camera position.

If you make crouchDrop 0 does your char still fall through the ground? If so it might be an animation issue.

the problem is when your first person controller crouches it actualy goes half in the ground and if you set croush limit to very hight your whole player will crouch under world

Take a look at this thread which deals with the issue you have.

How to Make the FPS Character Controller RUN and CROUCH