- Home /
OnCollisionEnter isn't working between two RigidBodies
I am trying to detect a collision between two 3d gameObjects (it is only detected about half the time):
A bullet, with a Sphere Collider and Rigidbody and Collision Detection set to 'Continuous' (because it is moving very fast).
and a log with a Capsule Collider and Rigidbody (with 'Discrete' Collision Detection).
The bullet has a script which calls OnCollisionEnter:
void OnCollisionEnter(Collision collision)
{
HitBox hitBox = collision.collider.gameObject.GetComponent<HitBox>();
if (hitBox != null)
{
hitBox.OnHit(damage);
}
Destroy(gameObject);
}
See my screenshot which shows the trajectory of the bullet going through the log. It's clearly going through it.
And this is what the Sphere Collider on the bullet looks like:
The weird thing is that when I remove the RigidBody from the log, then the collision is detected. But I want the Log to have a RigidBody so it will have gravity.
Also there is no custom Physics layering going on here, so you can rule that out. Please help! Unity version 2019.3.8
Answer by KoenigX3 · May 29, 2020 at 01:20 PM
Check the UnityDocs for Rigidbody.collisionDetectionMode. It says that you need to set the bullet to ContinuousDynamic and the log to Continuous.