Unity Physics: Trigger Colliders

Jared Amlin
Nerd For Tech
3 min readJul 31, 2024

--

Trigger collisions, also known as pass-through collisions, can be used to solve an assortment of behaviors. You can use triggers for dealing and taking damage from weapons and projectiles, playing cinematics and particle effects, spawning enemies and much more.

When two objects collide, you can use the OnTriggerEnter Unity method to get all kinds of information about the other object. Object name, position, rotation and any component attached to the collided object, can all be referenced on collision.

If you want a more in depth article about how the different Unity collision methods work, as well as the difference between hard-surface and pass-through collisions, please reference my article below.

This sample exercise uses a 3D model with an empty child object to act as the trigger.

The trigger object has a box collider with IsTrigger enabled, and a Trigger script.

Here is the size of the box collider.

These barrels have a capsule collider and rigidbody with gravity enabled. When they fall into the trigger, I am going to change the emission color and emission intensity of the small piece on the front.

The Emission and HDR is what I want to access here on the Material.

The Trigger script checks the other object on collision and gets the Mesh Renderer component. From there the material is accessed and the SetColor method is called, which takes a string parameter for the color assignment to be changed (emission) and the color to change to (yellow). The color is multiplied by 5, which will boost the emission intensity by pushing the HDR value above 1.

public class Trigger : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
other.gameObject.GetComponent<MeshRenderer>().material.SetColor("_EmissionColor", Color.yellow * 5f);
}
}

This is just one example of many when it comes to ways you can use trigger collisions to solve behavior problems.

Best of luck in your game development journey and thanks for reading!

--

--

Jared Amlin
Nerd For Tech

I am an artist and musician, that is currently diving headfirst into game development with C# and Unity3D.