The Fearless Enemies- Game Dev Series 47

Objective: Add aggressive behavior to enemies.

Imagine every enemies would use suicide attack if they are too close from Player to shoot laser. In this article, we will raise up the threat level of our enemies by giving them get closer to Player automatically.

Reaching to Player is just similar to the detect bomb we did couple days ago. We can simply use a detecting range to identify where is Player.

This would be a quick tutorial, all we need to adjust is our Enemy script.

Enemy script adjustment

First of all, create a variable to verify the detecting range.

With this range, we can check the distance between enemy and Player in every movement frame, which we can do it by using if statement.

In both of movement method, we use the same function “Vector3.Distance” to check if the Player is in range.

That is almost everything that we need to change in our code. If you just want some of your enemies to be aggressive, create a random lottery to pick up who should be the one.

As create the Detect Bomb, we can use the Gizmo to visualize the detecting range.

Visualize the range

Simply add one method in our Enemy script and you should see the range with wired sphere shape in preview.

Then, enjoy the crazy enemy waves!




A passionate gamer whose goal is to work in video game development.

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

Recommended from Medium

How to Create Ratels Wallet in Firefox?

My JS/Rails Project Battle, Ships!

Use Django To Create A Backend Application

Object oriented programming talk

CS 373 Fall 2021, Week 2: Robyn Fajardo

TWTW Week 3,ENT101 — Day and night thinking about BOT

What is Full Stack Developer? Key Skills Required Java, Python

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
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Adding a thruster speed boost on keypress

Working with Screen Space Reflections in Unity’s HDRP

Creating An Advanced 2D Player Controller Without Any Unity Components! (Part 1)

Quick tip — Upgrading your Unity project to High Definition Render Pipeline (HDRP)