I am working on a 2D game that uses a CharacterController. Everything works great, except for the fact that since the collider is a capsule, when you are on the very edge of a flat, rectangular collider it kind of dips down a bit and gets “stuck” on the rounded part of the capsule.
I’ve tried checking the normal.y and seeing if it is less than a certain value, and then disabling the collider, but I don’t think this is a good solution and I’m having trouble figuring out how to determine when to re-enable it. Does anyone have any solution to prevent this from happening? Thanks in advance!
I don’t know what you mean by “stuck” ? There was a bug in an earlier version of the flash exporter that would have character controllers get stuck inside other colliders if that’s what you’re experiencing. Otherwise it shouldn’t get “stuck” it should just slide.
Sorry, it doesn’t really get stuck. It technically does what it’s supposed to do, I’m just wondering if there is a workaround short of not using a CharacterController. Someone posted a video once with the exact problem:
Notice how the capsule sinks a bit at the edge of a platform.
Just a guess as I’ve never had to correct this problem:
Use a box collider. If you really need a rounded top for your character use a box for the bottom and capsule/sphere for the top. Plenty objects out there running around with multiple colliders as children of a parent object.
Thanks for the response. The problem with that solution is that it uses a CharacterController, and I none of the collision events would fire on the bottom portion of it.
The idea is you’re just using it as a “flat” surface to keep from “sinking” on platform edges. The capsule can still be used for collisions - the box can just be used for standing collision.
Or just scratch the whole idea and use a box collider instead of a capsule collider or you can still use both to trigger collisions as more complex models use multiple colliders without issues.
Well, I want to avoid using a BoxCollider and Rigidbodies since I have the movement perfect right now with the CharacterController. Adding the BoxCollider at the bottom of the object doesn’t seem to work. Other colliders (even if it is nested) don’t appear to play nicely with the CC.
I’m curious if a solution was found as well. It’s really sad how the character controller component isn’t flexible enough to replace the capsule collider with a more suited collider object.
The character controller is far from ideal for many situations especially 2D platformers. I would suggest ditching it and rolling your own setup with raycasts.
Thanks for the respond BBG,
but in my case, I really don’t want to give up the character controller because of all the useful properties (going up slopes, the Move method, etc.). Also Using Raycasts seem to be a pretty expensive solution for a problem that looks that simple. All I want is for the character to fall and not gets stuck on the edge.
I have been searching online and it seems like a lot of people making platformers have this problem but without any real solution. I hope someone can help. thanks!
Well not really, a few raycasts don’t cost much performance wise. Like you said you would lose the built in features of the CC and have to program it all on your own but at least it would then work how you want. This is the “real” solution.
Another option you could try is a box collider and rigidbody, locking any rotation axis which isn’t required. Then move it with forces.
I have same problem.and tried BBG’s Solution,but it will bring a new problem.when the box collider stay the air with a force to another, it will be drag by the side’s friction.
I had the same problem, and “solved” scaling in the platform’s collision. Your player see the mesh but no collision, you can scale in and the “stuck” issue improve a lot. I feel a little bit bad because looks like a hack but works