- Home /
How to crouch without falling through floor?
var controller : CharacterController;
okay I am trying to create a crouching script, but I am confused seeing as though my Player keeps falling through the collision mesh of the floor. Every time I crouch the player falls through the floor. What can I do so that the character, does not fall through the floor? I have tried "Yield get seconds passed", I have tried putting it in a series of steps but the game just ignores it.
How do I solve this issue?
function Update ()
{
if (Input.GetKey ("c")) {
GetComponent(CharacterController);transform.localScale.y = 0.2;
} else {
GetComponent(CharacterController);transform.localScale.y = 1;
}
}
Answer by tertle · Feb 03, 2011 at 12:23 AM
First big issue is...
GetComponent(CharacterController);transform.localScale.y = 0.2;
why is there a ; in the middle of it effectively your code reads
GetComponent(CharacterController);
transform.localScale.y = 0.2;
So the GetComponent isn't doing anything...
So you aren't performing the transform on the CharacterController necessarily if that's what you intended.
Not sure that'll fix your problem, but thought I should point it out.
Answer by cmonroy · Oct 23, 2014 at 04:26 PM
Simple: move the character controller a few centimeters up to the middle of your character. That fixed the problem for me.
Your answer
![](https://koobas.hobune.stream/wayback/20220613102530im_/https://answers.unity.com/themes/thub/images/avi.jpg)