- Home /
when crouch, falling through floors
Hey guys,
Ive been creating a character using the character controller. So I have written my own script to make it move, run, jump and crouch.
Now, everything seems to be working properly, except when the character uncrouches, that means, whe it stands up, it falls through the floor.
The issue is that, when using crouch, the controller.height is being altered from 2 to 1. So, when standing up, its 1 to 2. Thats exaclty the problem, when going back to the height of 2, that height goes through the floor so the character is now insered in the floor, thus falls.
I have already seen a solution where the gravity is "zeroed" or "stopped" for standing/uncrouching, but that really is not a solution for me because the player should be able to jump and crouch and also stand while in a jump.
Also I have tried smoothing this transition in controller.height, so it gradualy goes from 1 to 2 and 2 to 1, still not working, player falls through.
I have also tried giving a "little impulse" somewhat similar to stopping gravity, wich in this case it works, but again, not a good solution.
I have also tried setting the controller.center.y, wich would be an alternative way of changing the colliders position while standing so it doesnt go through floor but Ive had no success yet.
Would someone please give me any suggestions? I bet me and a lot of people would appreciate it!
Thanks in advance,
Answer by Loius · Nov 26, 2010 at 05:34 PM
You have to move the character controller (that is, transform.position.z += 1) so it's not clipping the ground. If it clips through something when its size is changed, it'll fall right through.
Just to add here, is this intentional, not to use the actual $$anonymous$$ove or Simple$$anonymous$$ove funcions of Character Controller?
Ok, still needs some adjustments, still very jerky movement but, lets see how it goes under testing with other movements like jumping etc... Thank you Vicenti for your help. :D
You could use .$$anonymous$$ove; that would let you check to make sure the character actually can un-crouch (if they're in a narrow pass, you could undo the uncrouch). Getting the animation to sync with the sudden movement is the tricky part; I haven't gotten around to implementing this yet in my game, unfortunately, so I don't have any concrete examples.
Yes, the .$$anonymous$$ove, because this is whats recommended for moving the character collider (at least from what Ive read so far), thats why I asked about it... Now, the thing that I think worked is because there is no interference with gravity, because gravity is being applied as a $$anonymous$$ove function... So by using translate, maybe this gave an extra moving possibility without altering gravity.
Your answer
![](https://koobas.hobune.stream/wayback/20220613084636im_/https://answers.unity.com/themes/thub/images/avi.jpg)