Search Unity

Collision detection without RigidBody2D ?

Discussion in '2D' started by BenoitFreslon, Dec 2, 2013.

  1. BenoitFreslon

    BenoitFreslon

    Joined:
    Jan 16, 2013
    Posts:
    166
    Hello,

    I'm new with Unity.

    I want to detect collision between 2 sprites.
    I add 2 Box Collider 2D but there is no collision detection.
    This script doesn't work :

    Code (csharp):
    1.     void OnTriggerEnter2D(Collider2D other) {
    2.         Debug.Log (other);
    3.     }
    4.     void OnTriggerExit2D(Collider2D other) {
    5.         Debug.Log (other);
    6.     }
    I have to add a RigidBody in one of my sprite to detect collison.
    But I don't want any physic engine in my game.

    Thanks.
     
    indeyetz likes this.
  2. spayced

    spayced

    Joined:
    Sep 14, 2013
    Posts:
    7
    You can't avoid the rigidbody. But you can avoid the physics.

    http://unitygems.com/mistakes1/

     
  3. unitylover

    unitylover

    Joined:
    Jul 6, 2013
    Posts:
    346
    Attach a rigidbody to your sprites with gravity scale set to 0 and a box collider and it will work. This is by in fact the way box2d is designed.
     
    indeyetz likes this.