- Home /
Why does OnCollisionEnter not work between a character controller and a rigidbody?
I am building a game where I have a weapon that shoots a projectile (with a collider and rigidbody), and an enemy with a character controller. In the enemy script, I have a OnCollisionEnter function that detects collisions between the projectile and the enemy.
When I shoot the projectile, it simply bounces off the enemy (so the collider is working). However, the OnCollisionEnter function never executes.
Is there any reason why the collision would not be detected? The strangest part is that the collisions were working previously and now they don't for some unknown reason.
The enemy has a collider? Did you mark both colliders as non-trigger?
Answer by aikitect · Feb 12, 2013 at 01:14 AM
I used OnControllerColliderHit and it works fine now.
Answer by JoeStrout · Jan 06, 2014 at 04:21 AM
That's not a general solution, though -- OnControllerColliderHit only fires when your character controller moves into something. It won't detect, for example, when your character is just standing there and gets shot by something.
I've just discovered this issue myself, and I'm still looking for a solution.
Well, why not both?
OnControllerColliderHit() to handle when your character bumps into something.
OnCollisionEnter() to handle when something bumps into your character.
I just tried this, appears to be reliable. However I also find that the object with the CharacterController component also needs to have a Capsule Collider component for the OnCollisionEnter() calls to work. I would have thought that wasn't necessary, since the physical behaviour is the same either way, but there you go.
Yes, that's essentially what I've ended up doing: adding a separate Capsule Collider component. I sized $$anonymous$$e slightly bigger than the CharacterController, so that it will actually hit stuff, but I guess with your technique (implementing both callbacks) that might not be necessary.
Answer by maminakyrtka322 · Sep 02, 2020 at 09:59 PM
Got same problem, OnControllerColliderHit works, colliders working, but OnCollisionEnter never executes. No info in whole internet( If you find a solution - pls tell me
Answer by MultidimensionalShow · Aug 21, 2021 at 11:32 PM
Place a second collider on the object you want your player to collide with and set it as a trigger.
Detect the collison FROM the object, checking the tag of the colliding object ( the player in this case ).
Then handle as needed.
Your answer
Follow this Question
Related Questions
Collision with character controller and cube not working 1 Answer
Object won't collide with FPS Controller 2 Answers
Two Character Controllers Colliding... 0 Answers
How to make a progress bar go up after two objects collide? 0 Answers
OnCollisionEnter being called without the colliders actually colliding 1 Answer