lerping colliders heights problem

hey i have a character controller and im changing the offset and height of my charactercontrollers capsule. my code:

void SetCol(string name)// this sets the colliders for the different states
	{
		if (name == "stand")
		{
			currentColRadius = colStandRadius;
			currentColHeight = colStandHeight;
			currentColOffset = colStandOffset;
		}else if(name == "crouch")
		{
			currentColRadius = colCrouchRadius;
			currentColHeight = colCrouchHeight;
			currentColOffset = colCrouchOffset;
		}else if(name == "prone")
		{
			currentColRadius = colProneRadius;
			currentColHeight = colProneHeight;
			currentColOffset = colProneOffset;
		}
	}

and in my update function im using

charController.center = Vector3.Lerp(charController.center, currentColOffset, colChangeLerpRate * Time.deltaTime);
		charController.height = Mathf.Lerp(charController.height, currentColHeight, colChangeLerpRate * Time.deltaTime);
		charController.radius = Mathf.Lerp(charController.radius, currentColRadius, colChangeLerpRate * Time.deltaTime);

the problem im having is that even though every thing is being lerped by colchangelerprate * time.deltatime my offset is taking longer to reach its destination/target value. and i don’t know why. so when my character controllers height is finished changing its on the same level and then the offset makes it move into the ground and fall through it

How do i fix THIS???

Thanks ~Scott

You will have better luck with these collider changes if you use Mathf.MoveTowards. I wrote you a C# script to show you how I would approach this issue. I hope this starts you down the right path!

StandCrouch.cs

Instructions: Place this script on a GameObject that has a BoxCollider and disable or remove the “Mesh Renderer”.
If you press the up arrow you will increase your stance until you are standing.
If you press the down arrow you will decrease your stance until prone.

using UnityEngine;
using System.Collections;

public class StandCrouch : MonoBehaviour {
	
	private Stance stance = Stance.Standing;
	
	private Vector3 standingColliderSizeValues = new Vector3(1.0f,2.0f,1.0f);
	private float standingCenterHeight = 1.0f;
	
	private Vector3 crouchingColliderSizeValues = new Vector3(1.0f,1.0f,1.0f);
	private float crouchingCenterHeight = 0.5f;
	
	private Vector3 proneColliderSizeValues = new Vector3(1.0f,0.5f,1.0f);
	private float proneCenterHeight = 0.25f;
	
	
	public float speed = 1.0f;
	
	IEnumerator ChangeStance(Stance _stance,float _speed){
		bool done = false;
		Vector3 targetColliderSizeValues = new Vector3();
		float targetCenterHeight = 0.0f;
		
		switch(_stance){
			case Stance.Standing:
				targetColliderSizeValues = standingColliderSizeValues;
				targetCenterHeight = standingCenterHeight;
				break;
			case Stance.Crouching:
				targetColliderSizeValues = crouchingColliderSizeValues;
				targetCenterHeight = crouchingCenterHeight;
				break;
			case Stance.Prone:
				targetColliderSizeValues = proneColliderSizeValues;
				targetCenterHeight = proneCenterHeight;
				break;
		}
		
		BoxCollider boxCollider = gameObject.GetComponent<BoxCollider>();
		Vector3 tempSize = boxCollider.size;
		float tempHeight = boxCollider.center.y;
		
		while(!done){
			tempSize = Vector3.MoveTowards(tempSize,targetColliderSizeValues,_speed * Time.deltaTime);
			tempHeight = Mathf.MoveTowards(tempHeight,targetCenterHeight,_speed/2 * Time.deltaTime);
			boxCollider.size = new Vector3(tempSize.x,tempSize.y,tempSize.z);
			boxCollider.center = new Vector3(boxCollider.center.x,tempHeight,boxCollider.center.z);
			if(boxCollider.center.y == targetCenterHeight && boxCollider.size == targetColliderSizeValues){
				done = true;
			}
			yield return null;
		}
	}
	
	void HandleInput(){
		if(Input.GetKeyDown(KeyCode.UpArrow)){
			int currentStance = (int)stance;
			currentStance += 1;
			if(currentStance > (int)Stance.Standing){
				currentStance = (int)Stance.Standing;
			}
			stance = (Stance)currentStance;	
		}
		else if(Input.GetKeyDown(KeyCode.DownArrow)){
			int currentStance = (int)stance;
			currentStance -= 1;
			if(currentStance < (int)Stance.Prone){
				currentStance = (int)Stance.Prone;
			}
			stance = (Stance)currentStance;
		}
		StartCoroutine(ChangeStance(stance,speed));
	}
	
	void Update(){
		HandleInput();	
	}
}

public enum Stance{
	Prone,
	Crouching,
	Standing
}