andrewm2211

1 answer · asked · Lesson: Creating Health Pickups · Course: C# Bootcamp for Unity

Why does "istrigger" have to be checked? What if you want to collide with a rigid body, and have it trigger something, bu...

Why does "istrigger" have to be checked? What if you want to collide with a rigid body, and have it trigger something, but you still don't want the player to walk right through it. like lets say a wall of spikes that just takes down some health. you want it to be a trigger, but you also don't want the player to just walk through them. Would you just have to have a separate object for the graphics (model of the spikes) and a separate object parented to it to be the trigger?
  • crew

    If you want a collision you’d use “OnCollisionEnter”. It has pretty much the same process as the trigger functions. So you’ll have OnCollisionEnter, OnCollisionStay, OnCollisionExit. That’s for when you want something to hit something but not go through, like maybe a character running into a wall.

    Also to clarify the "isTrigger" checkbox, that tells Unity to treat that collider as a trigger. If you have that unchecked it will still act as a solid collider regardless of whether or not you're using "OnTriggerEnter".