Resize Characterl Controller height Problem

Hi everyone

As i mentioned in a title i have problem with resizing character controler.
Its ok when i scale it down but when i scale it back to original ( bigger size ) it fall throught my ground collider is that any easy solution how to do this without falling throught?

Thanks :slight_smile:

because the scaling happens from the center, when you make it smaller the extent is less than what it was before but when you make it bigger the lower extent falls below the lowest terrain height. To fix this you also need to adjust the y position of the controller when u scale it. Two things that should help you.

Terrain.activeTerrain.SampleHeight(Vector3); // Gets the terrain height at a certain coordinate
GameObject.collider.bounds.extent // the extension of a collider from the center

/* So basically you can do this */
var oldPosition = GameObject.transform.position;
var height = Terrain.activeTerrain.SampleHeight(oldPosition);
height += GameObject.collider.extent.y * 2; // assuming the pivot is at the center
GameObject.transform.position = new Vector(oldPosition.x, height, oldPosition.z);

If the pivot point is at the center you may need the extent adjustment, however if it is at the bottom(i always set the pivot at the bottom for every models i create to avoid the problem) you do not need to compensate for the extent.

thanks, i get the idea it should work now :slight_smile: