- Home /
How to change box collider size without falling through the ground
I have to make a crouch animation, so i need to change the size of the collider to allow the character pass through small holes, but when I change the height the charachter fall through the ground, any help?
Does he fall through or stick through the terrain and stay like that without falling even further? When you change the height it will scale around the capsule's center (so subtracting some from the top and bottom). You might want to update the Center too to reflect this change.
He fall through, i tryed to increase height, but now it falls when he stands up :(
I had the same problem with my character for a delayed jump. When the user presses the jump key, my character needed to bend his knees and jump after a little delay.
To do this, I animated the collider to go up (because it was attached on its center, so the player went down with gravity), and then go back down. At this time, the collider went threw the ground and my player was falling ...
So I needed to modify my animation for the collider to go up and down slower than the gravity effects.
I think this is the same for you. You can get it smaller without any problem I think, but when it goes taller, you need to animate the y position and make it go upper quicker than it goes taller.
I hope you understand what I try to say :)
The real problem is that when the collider is just a little bit lower than the ground, it goes totally threw it, the whole thing is to avoid this little error. This is not a bug, It is how the engine works ...
Answer by Sequence · Jun 11, 2013 at 01:35 PM
I'm going to assume the change in size is instant and you don't have the size change slowly over time. You need to change the position as well as height when your character crouches otherwise the collider's bounds might go through the ground. You could change the character's Y position based on the new crouched height and the character's height before he crouched. A similar approach could be used when standing up.
Your answer
![](https://koobas.hobune.stream/wayback/20220613103941im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can I use a raycast to retrieve information from the collider? 2 Answers
Keeping speed while crouching in midair and remove clipping while returning to standing 2 Answers
Raycast problem trough the terrain 1 Answer
Prefab's collider2d.bounds.size is not set 1 Answer
Changing Box Collider size 4 Answers