- Home /
Character Controller won't collide with anything
I'm in 2D. I have a character controller on my playable character. He's moving great, however the character controller will not collide with anything under any circumstances (I'm using boxcollider2d on environment objects). It seems like the character controller, which purportedly comes with a collider built-in, shouldn't move straight through walls - or am I REALLY missing something about how this thing is supposed to work?
The docs say the character controller doesn't need a rigidbody (that's the point of having a CC isn't it?) and doesn't need a collider added to it. In fact, Unity won't let me add a collider or rigidbody to a gameObject with a character controller.
Things I've tried:
1. Toggling off "Is Trigger" on my collider object (and no, there is no such setting on character controller)
2. Adding a rigidbody2D to a child
3. Adding a boxcollider2D to a child
4. Using OnControllerColliderHit to write my own "don't walk through stuff" code (it never fires)
5. Adding rigidbody2D to everything in the environment (they all just fell off the screen - and they went straight through my player on the way without touching him, so turning gravity off is irrelevant).
6. Tearing my hair out.
Answer by Bunny83 · Nov 16, 2017 at 02:27 AM
The CharacterController is a 3D object. From the (3D) physics point of view the CharacterController is an upright CapsuleCollider. Of course it doesn't work with 2d colliders. The 2d and 3d physics systems have no relation to each other. for 2d physics Unity uses "Box2d", for 3d physics it uses "PhysX". If you want to use the CharacterController you have to use 3d colliders (SphereCollider, CapsuleCollider, BoxCollider, MeshCollider).
If you want to use 2d physics and 2d colliders you have to use a Rigidbody2D instead. There is no equivalent of a CharacterController for 2d.
Works like a charm. I suppose I really was missing something fundamental. Now if only there were a charactercontroller2D to make life a little simpler.
Omg I love you. I stuck in this problem for hours T_T... THX!!!!