- Home /
How would I stop my character from clipping through the walls?
my character keeps clipping through walls if I walk into them. The collision is happening, and I know this because there is some resistance when walking into a wall.
I suppose that I could just thicken the walls, but that would still have partial clipping.
Is there a code that will let me disallow movement in a certain direction if there is a collision in that direction?
hii . i have the same problem . i cant fix it . did u fixed it finally ? appreciate if u help me
That is something for a comment, not a question. Please keep that in $$anonymous$$d when posting.
Answer by lyzard · May 24, 2012 at 07:00 AM
the collider you attached to your character is probably not thick enough, if you are using CapsuleCollider, try changing the radius. If you are using CharacterController, try changing the radius or the skin width. In any case, in the editor when you click on an object with a collider and make sure that in the inspector the collider component is expanded, you can see what are the boundaries of the colliders you are using, this might be of great help for your issue
I'm using a box collider that encompasses the entire character model. The walls that I am using have a mesh collider.
Could I get another answer? Lyzard's would work but is less than ideal.
Answer by danielson317 · Aug 17, 2017 at 12:48 AM
I had the same issue with clipping through walls. Per Lyzard's answer I made the wall thicker and the player bigger and it stopped happening.
A little experimentation based on that knowledge and I learned
You can also slow the players movement down.
Use momentum instead of transporting the player. If you use momentum on key press with high drag clipping will be more difficult as you are passing the movement onto the engine instead of managing it yourself.
(safest but most high maintenance) set triggers and back your player up if they go to far past a boundary so clipping just pushes them backwards. (if (position > x_max) position = x -1)
I believe this is simply a performance vs. realism issue. The engine checks for collisions every frame. Your movement if it is fast enough can get the center point past the colliders center in that frame if it is set to move far enough. So slowing the player down and making the walls thicker both have the net effect of the player not being able to build enough speed to get past the center point of the collider within 1 frame. I suspect your FPS may affect this as well though. I have a bad video card and I am running in debug mode. This will be less prominent in a production release with a decent video card.
Answer by Zakalakin · Feb 05, 2014 at 12:22 PM
I'm having the same problem. I'm now going to cast a ray out in the direction I'm moving at the length of my speed, if it collides with an object I wont execute the movement script.