Variable First Person Controller Height

Hi all,

this is driving me crazing so I hope someone can help. I have a First person controller and i want the user to be able to vary the height with a Horizontal slider. Sounds easy huh? well I have cobbled together a script to do this, trouble is every time the user makes the character controller height bigger the character just falls thru the ground object.

Any Ideas anyone?

heres what I have so far:

var objectName = "First Person Controller";
var scriptName = "CharacterController";

var myScriptObject : CharacterController;
var newValue : float;
var currentValue : float;

function Awake()
{
   object = GameObject.Find(objectName);

    if ( object != null )
    {
        myScriptObject = object.GetComponent(scriptName);

        if( myScriptObject != null )
        {
			currentValue = myScriptObject.height;
            newValue = currentValue;
        }
    }
}

function OnGUI ()
{   
	if(myScriptObject != null)
	{
	newValue = myScriptObject.height;
	} 
	    GUI.Label (Rect (10, 10, 80, 20), "Height");
   	newValue = GUI.HorizontalSlider (Rect (25, 25, 100, 30), newValue, 0.0, 10.0);
  
   
}



function Update()
{
  
       myScriptObject.height= newValue;
}

To test your problem, I made a box in my game, added a character controller to it and changed the height. I noted that the box position did not change. However the capsule collider did. It got larger. Your character should be centered on the collider. Whatever height you add, you must add half that to the Y of the character collider.

Yea, thanks for that. I have since changed it so it scales the controller instead. Seems to work a lot better.

Yeah, I was going to say… when you change the size of the collider, it changes from the center, so you’re probably growing beyond the floor and thus, falling through. You need to scale the collider and offset the Y, so it doesn’t drop through.