- Home /
Why OnCollisionEnter cannot detect collisions between colliders?
I have a transform moving, using Transform.Translate; When I add a rigid body as a component to the game object, my OnCollisionEnter works when the game object hits another collider. But when I add only a collider rather than a rigid body, my OnCollisionEnter isn't called.
Why OnCollisionEnter cannot detect collisions between colliders?
Answer by Invertex · Jan 25, 2014 at 10:24 AM
Because no collision is technically happening if there is no rigidbody to take force into account. It's just 2 colliders who happen to be occupying the same space, because they have been translated there.
If you absolutely have to use Transform.Translate, then set the Rigidbody to "Is Kinematic". But the way you're supposed to move a rigidbody is with rigidbody.AddForce() or setting the rigidbody.velocity directly.
Thank you I 'm trying your way right away. But according to the manual,
OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
I thought that should work between 2 colliders. Am I wrong?
Yes, because there needs to be a rigidbody in that equation, for physics calculations to happen. For a physics calculation to happen, something with physics needs to be there, i.e: a rigidbody.
Collision is a physics calculation. If you don't want to go that route, you could use Raycast's ins$$anonymous$$d, or a SphereCast, to check if an object of a certain Tag or Name, or Layer is withing a certain distance of your object. https://docs.unity3d.com/Documentation/ScriptReference/Physics.SphereCast.html
https://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=raycast
No need for metaphysics. One of them needing a rigidbody is just a rule. Look at the last line, 2nd P of the manual: http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html
I always assumed it was just an optimization. If it checked stationary objects, just in case you moved them by hand, physics would run way too slow.
Your answer
Follow this Question
Related Questions
Collision Only being detected on one of the objects involved in the collision - C# 0 Answers
Cannot get collision to do anything 1 Answer
simple onCollision and onTrigger problem 1 Answer
OnCollisionEnter not triggering when two rigidbody collide via Instantiate 1 Answer
Which Object Calls OnCollisionEnter()? 3 Answers