- Home /
How to succesfully implement OnCollisionEnter?
I'm pretty sure I'm missing something very simple but, alas, my line of sight is blurrying my vision here. Please help me.
In order to show my problem in a simple scenario, I created a new scene.
Added a simple 3D Cube, clone it and move it near the original.
Inspector cube a: http://cdn1.npaste.com/image/original/1470805079/obogfk.jpg
Inspector cube b: http://cdn1.npaste.com/image/original/1470805127/oboghe.jpg
Attached a simple C# behavior component to Cube b: http://cdn1.npaste.com/image/original/1470805171/obogix.jpg
Press play and move the cubes so they can kisskiss: http://cdn1.npaste.com/image/original/1470805236/obogk4.jpg
Nothing... Needless to say, I feel very hmm... limited (not to say super stupid) in how to implement a simple collision detection.
I came across with this problem at attaching a similar script to a fired rocket towards some asteroids.
Any ideas of what am I missing here? Thanks in advance.
Answer by shriya · Aug 10, 2016 at 05:23 AM
Attach a rigidbody to the cube. Hope it helps.
Ok, adding a Rigidbody to one of the Cubes, the event occours. Is it mandatory to have a Rigidbody to trigger either OnCollisionEnter or OnTriggerEnter?
Thanks for the quick response @shriya
Sorry, I didn't read first: https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html "Notes: Trigger events are only sent if one of the Colliders also has a Rigidbody attached."
Thank you and sorry for my dumb question.
Answer by _Yash_ · Aug 10, 2016 at 06:13 AM
open this : https://docs.unity3d.com/Manual/CollidersOverview.html
and scroll down to Collision action matrix
Great! I'll keep this in $$anonymous$$d from now on. Thanks mate!
Your answer
![](https://koobas.hobune.stream/wayback/20220612090525im_/https://answers.unity.com/themes/thub/images/avi.jpg)