Using OnCollisionEnter versus OnTriggerEnter

Ahad L. Amdani
2 min readMay 18, 2021
Basic collision detection — enemies can be hit by lasers, or can hit players (so far)

For the case of Sovereignty, there aren’t going to be any hard surface collisions. Why do I bring that up? Because that means we’re primarily going to be leveraged OnTriggerEnter for our collisions as we have things “pass through” each other and determine how to interact upon their first touch — like collecting a coin or a health pick-up that’s laying around in a game. The primary use of OnCollisionEnter is for those hard surface collisions that leverage the physics engine and the like, which for now, our game isn’t planning on supporting. I’m trying to get the basic mechanics ironed out for now, and in our over-the-top view arcade-style space shooter, we don’t really need to have that kind of advanced collision detection. Just knowing things “touched” is good enough in order to execute appropriate behavior.

If an enemy is collided upon by a player or a laser, it takes appropriate action.

For now, the “damage” to the player is a simple lives/hits and the main mechanic is yet to be determined. I’m thinking we’ll start off with shields that can take 3 laser type hits, 2 missile type hits, 1 auxiliary type hit or a physical ship impact, but provides no defense against an ult type hit. To enable detecting the collisions with OnTriggerEnter, we’ve added a rigid body to the enemy prefab as well as the laser prefab in this instance, removing the gravity flags on both so that Unity’s basic physics will kick in and trigger the collision hooks.

--

--