- Home /
Character Controller collision
I've been looking for an answer to this for a while now but I can't find it anywhere.
It's a very simple question: Where do I control what happens when my character controller collides with something?
My game object contains nothing more than a character controller and a script. Simply declaring onCollisionEnter in my script obviously doesn't do anything, since the method is never called.
So I need to know where I can add code that executes whenever my character controller collides with something.
Thanks in advance
Answer by Habitablaba · Jun 09, 2017 at 05:38 PM
The simplest answer is to add an appropriate Collider component to your player object, and one to anything that you want to collide with.
The less simple, and potentially much more awful solution is to do distance checks between your object and whatever you may collide with. If you have only one or two things you're checking collision with, this might be fine, but I'm sure you can see how this would get out of hand pretty quickly. In this case, you could do these calculations in the Update method.
Yeah, I came up with this solution a while after asking (took a few days to moderate)
But i find it odd that we can't access the collider included on the character controller...
There is no collider included in the character controller. If you have a character controller which references a collider, then you need to add it as a component on the player. Once you've done that then yes, you can absolutely access that collider.
Well, If you add the character controller component to an object you can see that it seems to be using sort of a capsule collider. But indeed, it's not an actual collider component that you can access, which i find odd.