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

Python Training — Introduction — En Version

Rhythm Quest Devlog 11 — Odds and Ends

Everything You Should Know About Fullstack Web Development

Auto-scaling a group of EC2 instances

The Last (Engineering) Dance

How to install a virtual Donkey Car on your PC using docker

Using templates in Azure DevOps Pipelines: What, Why and How!

These 5 Technical Interview Questions Took on My Nerves

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

Rapid Prototyping with the New Input System in Unity 2021

Player Movement in Unity

Building a Custom Cinemachine Virtual Camera Zoom Feature with One Button in Unity

Lives and Respawn System in Unity