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

My Top 3 Advice For Anyone Learning To Code

A man tying his shoe lace with “Are You Ready?” text on the track next to his left foot

Install Fedora 26/27/28/29 on MacBook 4,1 White (or Black)

Scrum Events — Product Backlog Refinement

CEO Diary #5 Future of Work — Dictation

Why software project delays shouldn’t be ignored

35 Important Terminal Commands You Should Know.

Using the dailymotion API to create a simple UWP application

A review of the LoPy microcontroller

PyCom LoPy Device

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

Toss a Coin: Creating a Simple Distraction System (Game Dev Day 62)

How to stick decals on the Spatial Mesh of Hololens2

Benefits of Prototyping with Cubes

How do hackers use your information for identity theft?