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!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Varnish “Backend fetch failed”

Accept the three dimensions length (l), breadth(b) and height(h) of a cuboid and display surface…

c program

My journey with software development

CS371p Spring 2021: Marcus Mao

Daily Progress: Refactoring AWS Manager and Uploading to AWS.

Thinking in : Linear Algebra

Some people might take interest Some may support you in your quest But at the end of

MPLS Network Providers in Elder Street #MPLS #Suppliers #Elder #Street https://t.co/VMWb8oIasS

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
Adam Reed

Adam Reed

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!

More from Medium

What’s new in PVS-Studio in 2021?

Attack while jumping

MVC Pattern in Unity — Less Code Dependency and Better Code Architecture

Creating static IP proxy for C# run in GCE using squid.