Handling collisions in Unity

Michael Kline
2 min readMar 21, 2021

Most types of games involve some sort of collisions between game objects, like a racing game where cars might collide with each other or a platformer where the player must reach certain checkpoints in the world. Both use collisions, but in different ways.

In a racing game, you want cars to behave how they would in the real world when a collision occurs. Both cars have solid colliders on them, and should collide and then bounce off of each other. If you want to be able to record data about the collision when it occurs or perform some other action, you would use Unity’s built-in ‘OnCollisionEnter’ function on a script attached to either of the cars. OnCollisionEnter will be called the moment the cars’ colliders come in contact with each other.

On the other hand, say you have an object in a platformer game that you do not want to be solid and want the player to simply walk through but still register the collision. A checkpoint would be a good example of this. In that case, you would mark ‘Is Trigger’ as true in the rigidbody component of this object, and use the ‘OnTriggerEnter’ function to register the player walking through the object and perform any game logic there.

For the space shooter game, I am using OnTriggerEnter for the collisions between the laser and the enemy because I do not want the laser to be a solid object and push the enemy out of the way. I want to destroy the objects when they touch each other.

And this is what happens when you forget to enable the ‘Is Trigger’ option for your colliders. Oops! Though comical, this is not the intended functionality.

--

--