Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

OnCollisionEnter2D is never called

Discussion in '2D' started by jachepe, Sep 25, 2014.

  1. jachepe

    jachepe

    Joined:
    Sep 25, 2014
    Posts:
    2
    Hi!

    I want to check when two objects 2D collide. Each objects have a "Box Collider 2D" and one of them has the following script:

    Code (CSharp):
    1. void OnCollisionEnter2D(Collision2D collision){
    2.         Debug.Log("collision");
    3.         if (collision.gameObject.tag.Equals ("rock")) {
    4.             RotateWorld.stop = true;
    5.             Debug.Log("collision with a rock");
    6.         }
    7. }
    when the two objects collide, never call this function. If a one of them have a "Rigidbody 2D", then call this function but the object that has rigibody, is affected by the physical and I don't want this, I only want to check the collision. If I check "Is Kinematic" of the rigidbody, never call this function.

    Any idea?

    Regards.
     
    Last edited: Sep 25, 2014
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    One of the objects needs to be a non-kinematic rigidbody in order for collisions to work.

    --Eric
     
  3. jachepe

    jachepe

    Joined:
    Sep 25, 2014
    Posts:
    2
    Thanks for your answer.

    If you need that one of the objects has a non-kinematic rigidbody and it's affected by the physical, How I can check the collision with two objects 2D without affecting the physical?

    Regards.