Search Unity

Collider IsTrigger: When to use and not to use?

Discussion in 'Physics' started by ChrisX, Apr 8, 2015.

  1. ChrisX

    ChrisX

    Joined:
    Feb 13, 2015
    Posts:
    63
    Hello all!

    I'd like to ask about the programming concept here. Where do you think IsTrigger better used on?

    If I have to guess, enemies should be put with IsTrigger. However, if I do that, the enemy just won't stand on the ground, they just drop down to oblivion. Is there a way to ensure that the enemy stands on the ground, act like a Trigger to the player, and not being controlled in a kinematic way?

    Thank you.
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,331
    Triggers are for everything that has to react to other objects intersecting with them, but are not going to use physics. Non-triggers are for objects that move around, hit stuff, and gets hit by stuff.

    Not quite sure why you believe that enemies should be trigger colliders - care to elaborate?
     
    surbhi233 and Zacharyyyyyy like this.
  3. ChrisX

    ChrisX

    Joined:
    Feb 13, 2015
    Posts:
    63
    Consider this scenario:
    1. You are a player that walks on a ground. Your enemy does the same too.
    2. You want it that if you are hit, you just enter an invincibility frame (that is, you are not bounced off)

    To fulfill point#1, you need to have the enemy be rigidbody, otherwise they fall through the ground. But to fulfill point#2, you need to have the enemy be trigger, so you could get inside the enemy while being on invincibility frame.

    I'm trying to accomplish both. I tried assigning multiple colliders, one for the trigger, one for the non-trigger. It works somewhat but I thought there could be more optimal ways to do so.
     
  4. SnakeTheRipper

    SnakeTheRipper

    Joined:
    Dec 31, 2014
    Posts:
    136
    If you are hit by what ?
     
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Add multiple colliders. One can be a trigger, one not. Easy.
     
  6. ChrisX

    ChrisX

    Joined:
    Feb 13, 2015
    Posts:
    63
    If you are hit by the enemy, of course. Colliding body together.

    Again, like I said, multiple colliders seems to be the way to go, but I am simply wondering if there are more optimal ways, or the multiple colliders are really the most optimal.

    Now the problem is where to put the non-trigger collider. I mean, it'd be weird if I can get inside the enemy while in invincible frame, and suddenly I hit the non-trigger collider and hits an invisible wall inside the enemy instead of going through them.
     
  7. topzbroken

    topzbroken

    Joined:
    Mar 3, 2015
    Posts:
    5
    Why not use layers? Make the player collider's layer in a different one that the enemy collider's layer.
    That way you can make the enemy pass through the player's collider.
     
    Impulseproger and Kiwasi like this.