Search Unity

Making only certain objects pass through each other

Discussion in '2D' started by RandomActStudios, Jul 22, 2014.

  1. RandomActStudios

    RandomActStudios

    Joined:
    Jul 21, 2014
    Posts:
    15
    I have 2 separate spawners on each side of the map that spawn enemies that start moving toward each other. Is there a possible way to make it so that the enemies that are spawned still collide with the ground but don't collide with each other?
     
  2. Pyrian

    Pyrian

    Joined:
    Mar 27, 2014
    Posts:
    301
    You're looking for Layers. You create Layers in Project Settings->Inputs & Layers, then in Project Settings->Physics2D, you can set which Layers collide with which other Layers. You can even set a Layer to not collide with itself! Each GameObject is assigned to a Layer in the Inspector near the tag setting.
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Yep, that's probably the right answer. If you need more fine-grained control over this, you can do it on a collider-by-collider basis, too. Beware that this is going to be very slow in your initialization though. If making the layer ignore itself in collision, that's far and away the better option.
     
  4. RandomActStudios

    RandomActStudios

    Joined:
    Jul 21, 2014
    Posts:
    15
    Thanks a million