Search Unity

Is there a way to create multiple colliders that only apply to certain respective tags?

Discussion in '2D' started by jleven22, Jun 12, 2019.

  1. jleven22

    jleven22

    Joined:
    Mar 26, 2019
    Posts:
    421
    For instance, I'd like one player collider to only interact with walls, and another player collider to interactive with enemies and other players.

    Anyway to either ignore all or ignore selectively?
     
  2. LivDominus

    LivDominus

    Joined:
    Aug 13, 2018
    Posts:
    5
  3. jleven22

    jleven22

    Joined:
    Mar 26, 2019
    Posts:
    421
    See I already looked into this, and this won't work.

    My specific situation - my player has one collider for movement and another to act as a hitbox for enemies. The hitbox is much larger than the movement collider, which only covers the legs (that way it can overlap sprites above the legs).

    So what I need is to figure out how to have each collider apply to either only specific layers or tags only.
     
  4. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    On the contrary, this sounds like exactly what you need.
    • Separate your colliders on child GameObjects of the player object.
    • Set the layer of the child object containing the movement collider to a layer that only interacts with terrain.
    • Set the layer of the child object containing the hitbox collider to a layer that only interacts with enemies.
     
    Last edited: Jun 13, 2019
  5. jleven22

    jleven22

    Joined:
    Mar 26, 2019
    Posts:
    421
    THAT IS VERY SMART!

    I will be trying this. Thank you!