- Home /
How to prevent the character controller sometimes passing through walls?
We have a character with movement, and it works nicely most of the time. It's made up of unity's CharacterController, our own input controller (in place of, for example, ThirdPersonController). This character happily moves around the level, and bumps into stuff and everything is apparently fine. Except...
Sometimes, the character slips through a collider. I can't narrow this down much, as it happens so rarely. I've never seen it happen:
Through terrain
Through horizontal colliders
I most often see it happen:
Through my "invisible walls" (box colliders surrounding the level)
When running nearly parallel to a wall
When jumping at a wall
Where there are multiple colliders in close proximity
I suspect it may be related to the speed the character is moving (but the speed should should never be fast enough to step right through the collider in a Move)
Any help on this will be greatly appreciated!
Answer by Meltdown · Aug 10, 2012 at 05:47 PM
Try attaching this script to your gameObject that has the character collider.
Hi Greg, thanks for the link. I just tried it - unfortunately I'm still slipping through things :(
Any other ideas? I'm considering "kill the player when they're somewhere they shouldn't be" but that could get increasingly messy.
You can try increase the scale of your scene and your colliders. You can also try adding another box collider or capsule collider to your character. Add it onto another gameObject on your character.
Ok, I will try the other collider thing now.
Out of interest, what sort of scales might cause problems? At the moment the character is roughly 1 unit tall, should it be bigger/smaller?
Smaller scaled environments usually caused problems for me. But more for fast moving objects. You might want to make your characters about 3 or 4 units tall.
No improvement when using another collider, still occasionally passing through
Answer by linoB · Jun 01, 2014 at 05:31 AM
I encoutered the same situation this week and I think I've found the solution. I suppose that your charactercontroler center Z is not set to 0.
Mine was at .09 and I were able to go through most of my vertical collider when walking along and turning the camera.
After doing some tests, I found out that setting back the Z to 0 and now it doesn't happen.
So just set it back to 0 and this should go alright.
If my english is bad please excuse me, i'm french speaking , I hope this will help.
Your answer
![](https://koobas.hobune.stream/wayback/20220613075451im_/https://answers.unity.com/themes/thub/images/avi.jpg)