Collider IsTrigger: When to use and not to use?

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.

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?

2 Likes

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.

If you are hit by what ?

Add multiple colliders. One can be a trigger, one not. Easy.

2 Likes

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.

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.

2 Likes