Adding Multiple Collision Detections To Your Enemies

Something that you gotta keep in mind when working with collisions is the priority levels of the collider components that you add. If you have a collider on a parent object, and another collider on the child object, the parent will detect collisions made by the child, but the child will not detect collisions made by the parent.

This is important when you are applying your scripts as well since you will have to take these factors into account when handling the collisions within your scripts.

So I started work on a new enemy for my 2.5D Space Shooter game that can detect when it’s close to the player and then turn to try and ram it. I added a large collider to the parent object that spanned the range I wanted my new enemy to check for the player, along with a script to handle most of its functions such as receiving damage and moving the enemy. Then I added another collider to a child object which only covered the parts of the enemy’s body that can be hit by the player. The script attached to this child object handles the collision detection for receiving damage and then calls the damage method from the enemy parent objects script.

If I had tried to detect the player and its attacks with the parent object that contains the large collider or put the large collider on a child object, then the player would be able to damage the enemy by colliding with or shooting the enemies detection range collider.

After that, it was just a matter of adapting my heat seeker missiles script from my previous article for this enemy. Let’s check em out!

Hi, my name is Adam Reed and I am a software engineer specializing in Unity and C# development. Feel free to scroll through and check out some of my work!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store