Enemy AI (part 2)

Pausing the movement of your Enemy during Idle Animation

Now that we have our enemy AI moving towards point A to point B, it is time to make the enemy pause during the idle animation.

Moss Giant Script:

Within the Moss Giant script we are going to need to gain access to the Animator component, so create a handle for the Animator. Since the Animator is located as a child object, we need to use the “Get Component in Children” function.

Next in the override Update method we need to pause the movement only when the idle state is playing. In Unity there is a special script that can track and compare the current state to the require state to toggle an action. This method is called “Get Current Animator State Info(0)”. The int number that is in brackets determines the layer of the Animator you are working on. Base Layer will always be Zero. This will allow Unity to check for states and we can use the “Is Name” to search by a string.

Since we don’t want the Moss Giant to do anything other than play the Idle animation, we can just use the “return” function to let the animation play until finished. Then the Animator would transition to the walking state causing the movement to happen.

To pause the Moss Giant when it reaches to the second point, we can toggle a parameter to let the idle condition play just when the Moss Giant reaches the next destination.

The best way to do this is inserting the Trigger condition just when the Moss Giant as reach the current position. We have the best situation within the Movement method where we setup the next destination via ping pong movement.




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

CS373 Spring 2022 — Week 12

Announcing KrakenD 1.0

The Developer’s Guide to Lending in Xero

Applying Structured concurrency in Kotlin: Part II — Creation

6 Common Challenges When Migrating To The Cloud And How To Overcome Them

Extract text with OCR for all image types in python using pytesseract

Jobs-as-Code; its origins and its value in the world of DevOps

Realtime Database Triggers with Firebase Functions

Cloud Functions for Firebase with logo

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

Adding Challenge — Limited Ammo Count

Enabling Unity Ads

Level Design in Unity Part 2: The Walls

Script Communication in Unity using GetComponent