Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I created a sphere object, added a rigidbody component (no kinematics) and attached a script to it like this:

function Update () {
}

function OnCollisionEnter(collision : Collision) {
    Debug.Log("OnCollisionEnter");
}

I then created a cube under the ball, added a box collider component with no trigger of course.

Then, when I run the game, the ball falls down onto the cube, but nothing happens. The OnCollisionEnter function isn't called.

What should I do?

share|improve this question
3  
Has the ball a collider attached too? –  Heisenbug Mar 10 '13 at 12:27
    
well...no...let me try this. –  namiheike Mar 10 '13 at 12:38
add comment

1 Answer

up vote 4 down vote accepted

I move the comment here, so we can eventually close the post.

Remember that both GameObject MUST have a Collider attached in order the OnCollisionEnter to be called.

As side notes:

  • A MeshCollider cannot collide with another MeshCollider.
  • Even if your colliders as marked as trigger, at least one of the 2 GameObject involved must have a RigidBody attached.
  • Collision between GameObject can be selective enabled depending on the layer the GameObject's belong to. Have a look at Layer-Based Collision Detection.
share|improve this answer
    
well, in docs, it says, both of the objects must be rigidbody or collider. In my case, one of them is rigidbody and the other one is collider...and it doesn't works... –  namiheike Mar 10 '13 at 14:47
    
No, it doesn't says "or". Doc says: "When a collision between two Colliders occurs and if at least one of them has a Rigidbody attached, three collision messages are sent out to the objects attached to them." So both must have a collider and at least one of 2 a RigidBody attached. –  Heisenbug Mar 10 '13 at 14:50
    
Good bullet points to add: Each object's respective layer must be enabled for collision in the PhysicsManager, and the ability of an object to collide with another is further defined by the collision action matrix at the bottom of this page: docs.unity3d.com/Documentation/Components/… –  michael.bartnett Mar 10 '13 at 18:20
    
@michael.bartnett: good point. I've add it thanks. –  Heisenbug Mar 10 '13 at 19:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.