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.