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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

I have a problem various Colliders on one Gameobject

Discussion in '2D' started by Gistiv, May 7, 2014.

  1. Gistiv

    Gistiv

    Joined:
    Apr 22, 2014
    Posts:
    13
    Hi Unity Community,

    I got a problem with my 2D game!

    In my scene i've got an enemy which walks from the right to the left and if my player hits the circle collider(representing the view) of the enemy he's following me(the player) until I leave the circle collider. But the enemie has another collider which I used for the collision with the bullets of my player. Now when the bullet is hitting his "view" collider the enemy dies because both of the colliders are triggers!

    My question is: Is there a possibility to manage the "view" thing otherwise or can I give the colliders tags or something like that to handle the differnet collisions?!

    Greetings Gistiv
     
  2. playmonkey1

    playmonkey1

    Joined:
    Sep 20, 2013
    Posts:
    60
  3. Gistiv

    Gistiv

    Joined:
    Apr 22, 2014
    Posts:
    13
    Thanks for the fast answer playmonkey!

    Right now I handle the Collison with the Distance between the bullet an the enemy:

    Code (csharp):
    1.     void OnTriggerEnter2D(Collider2D other)
    2.     {
    3.  
    4.         if (other.gameObject.tag == "Enemy"  
    5.                           Vector3.Distance(other.transform.position, gameObject.transform.position) < 0.75)
    6.         {
    7.             Destroy(other.gameObject);
    8.             Destroy(gameObject);
    9.         }
    10.     }
    but I think I'll change it because it's much easier to handle with such a childobject....