Creating Enemy Shields; One feature, multiple answers

There‘s not only one solution to a problem to solve. There are many ways to solve problems.

Revisiting the 2D Space Shooter project. I was going through some tasks, and decided to work on implementing Enemy Shields.

Objective: Creating an Enemy Shield behavior in a creative and unique way to make it work through trial and error and a lot of testing.

To begin this process, I duplicated my Player Shield GameObject.

We will go into the Enemy Prefab and make our new enemy shield a child of the parent Enemy object.

Implementing the Enemy Shield behavior.

The Enemy Shield needs to have its own script attached.

Let’s break down what we’d need to create the Enemy Shield logic.

  • A Collision Detection of OnTriggerEnter2D
  • A health amount variable set globally
  • Reference to the PlayerProjectile class script
  • Component access to the Rigidbody2D
  • The GameObject the script is attached to

Now lets see how I made this particular system work.

I was able to approach this scenario creatively, and in a way I did not know after testing that this was one way to implement this feature.

Additionally, we need to see if the other gameObject’s tag will be detected by a PlayerProjectile.

If we did that successfully, we need to get inheritance of the PlayerProjectile script.

From here we get the Rigidbody2D component and go into the properties:

  • collisionDetectionMode = collisionDetectionMode.Continous (Ensures all collisions are detected when the Rigidbody2D moves)
  • collisionDetectionMode = collisionDetectionMode. Discrete (Only collisions are detected when the Rigidbody2D is moved to a new position)

Using the discrete property, it worked perfectly for my implementation; And I’m sure there are many other ways to accomplish this same feature.




Game Developer focused in Unity with experience in Unreal Engine, Former Race Car Driver

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

Recommended from Medium

Aiir is hiring a developer

The world of *Ops: DevOps, SecOps, and DevSecOps

Mochi.Market x Ecio Giveaway

Move Your Kubernetes Stack to Istio: A Simple Example

What is Big O Notation?

Math in Unity : Grid and Bitwise operation (Part V)

How to quickly embed python in your C++ Application

Using Java’s .split() to Find First Occurrence

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
Zac Bogner

Zac Bogner

Game Developer focused in Unity with experience in Unreal Engine, Former Race Car Driver

More from Medium

Hidden Shortcuts to Make Level Design Easier in Unity.

Creating Double Jump!

Finding Work: A leap of faith

Dynamic Level Loading in Godot