Resuming Enemy movement

Resuming enemy movement based on player distance

Continuing from the previous article found here. We are going to finish up the enemy skeleton AI where we allow the skeleton to resume the movement after the player has traveled a certain distance.

Enemy Script:

In the enemy script, we are going to create a handler for the player transform, this transform component is going to allow us to determine the distance between the player and the desired object.

Make sure that the Serialized Field is used to you can import the player in the Inspector

Next we are going to create a new float variable called “Distance” which will be made from a Vector3 of the two comparing objects. (the Player and the current Target).

make sure to use the local position to prevent calculations within world position

In the If statement we are going to state that when the distance between the player and the current target is greater than 2.0f we are going to resume the walking animation and movement. We achieve this by making the bool “isHit” set back to false and also the animation bool “InCombat” is set to false as well.

Finally in the just to touch up one more potential area is in the public override update where we have the enemies pause when they enter the “Idle” state. We just need to add in one more condition which is the animator state “In Combat” must be false.

Finally we can see that once the player has walked away a certain distance, the skeleton will resume its walking animation and movement from point A to point B.

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

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

Recommended from Medium

Writing Mandelbrot Fractals with Hooks and Forks

Building the clone of website NYKAA MAN

What is “Props” and how to use it in React

Lab 6: Capacitive Sensing with Piezo

Why React divides so much…

Searching the College de France — Part 3

An introduction to visual automata-based programming in Rosmaro

React + Express API on Heroku

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
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

More from Medium

Enemy Hitboxes

My journey becoming a Unity game developer: 2.5D

Creating A Game Manager Class In Unity

Using Decals in Unity