Gun Shot Detected!- Game Dev Series 132

Quick guide: make enemy change their action state into Chase when got shot.

In this tutorial, we would make the action state Idle of enemy as a pre-action before chasing Player. In concept, when a zombie got shot, it should tracking the source of gun fire by instinct and move toward it. We would create this behavior to our enemy.

Detecting range

In Enemy script, to make a detecting area, we need to set a float to enemy.

With this float, we can detect whether the distance between enemy and Player is less than the detecting range.
Do this checking in Update().

Then we can make the Enemy state change into Chase.

Now our Enemy would chase Player when in range.

Gun shot response

The next would be responding to the gun shot.
As in my project, both Enemy and Player shared the same script to deal with damage. We can simply add some lines in it to make enemy can response to gun shot.

First create a public method in Enemy script to change the state.

Then in Health script, we can call this StartChasing() method when being attacked.

Once done, set the tag of Enemy to “Enemy” to make this code can process.
When you attack an Enemy in game, it would start chasing you!




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

About Local Space and World Space- Game Dev Series 121

Executable specifications — the path of least resistance

Role-based Authorization with Active Directory for GridGain

Jenkins after installation configurations

Can’t Contain Poop — Container Security CTF

Convert SavedModel to TFLite Model with Signatures

Top 9 .Net Trends to Dominate in 2022

So you want to install an Apache Web Server in Centos?

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

The new Input System: installation

Unity Observers

Adding another powerup — Shields

Using Decals in Unity