Hi there! I consider myself somewhat intermediate with scripting, but recently I’ve been having trouble understanding the difference between OnTriggerEnter and OnCollisionEnter. I know that you use the ‘Trigger’ variation if whatever your colliding with has IsTrigger checked in their Collider component, and vice versa for OnCollisionEnter. But I know you need to use the ‘Trigger’ variation if the object that the script is attached to has IsTrigger checked to detect a collision from it. I don’t understand because with OnTriggerEnter it detects collison is one or both of the objects have IsTrigger checked. Let’s say we have two variables: the GameObject the script is attached to (mainGameObject), and the variable we want to detect collision with (detectedGameObject). What if I wanted to detect collision between the two objects only if detectedGameObject had IsTrigger checked? The collision would still activate if the mainGameObject had IsTrigger checked, or is both of them had IsTrigger checked. Would I just have to use an if statement to check if only one had IsTrigger checked or what? Any explanation would be much appreciated, thanks! ![]()
Yup it’s as simple as that, on your main game object just check for the collision properties of the other:
function OnTriggerEnter(other : Collider)
{
if (other.isTrigger)
DoSomething();
}
We use OnTrigger because OnCollisionEnter passes in Collision not just the collider involved. (Collisioninfo provides contact points, impact velocity, and more) We don’t need all that data, so it’s probably simpler and faster to use OnTrigger in that case.
1 Like
Thank you very much, that helps me a lot. It was starting to get pretty confusing.![]()