In part 9 of this tutorial series we learned how to work with animations in Unreal Engine and we animated our Parasite enemy.
In this part of the tutorial we are going to code enemy AI behaviour and we are going to wrap up our game.
Creating The Enemy AI
Inside the BP_Parasite_Enemy Blueprint, create a new float variable, give it a name Wait Time, set the default value at 5 and check the Instance Editable checkbox:



Don’t forget that we made that variable Instance Editable which means we can change the value of it on the instance of the Blueprint.
After we wait for the specified amount of time, we are going to call a new function that will move the enemy towards the player.
Inside the graph, Right Click and search for AI MoveTo function which is located under AI category:

The AI MoveTo function takes a few paramaters. One of them is the Pawn parameter which is the Actor that will be moved with the AI MoveTo function which in our case is the Parasite enemy.
For that parameter we are going to get a reference to self by Right Click and search for self:


The next parameter that we need to provide is the Target Actor which will tell the AI MoveTo function where to go.
Since we are going to make the enemy follow our PlayerCharacter, we can get a reference to it by using Cast To, but since we already set up the BP_PlayerCharacter to be the default pawn, we can pass the returning value of the Get Player Character function to the Target Actor parameter:

You can copy the nodes from here:
AI Nav Mesh Bounds Volume
The code for the AI behaviour is done, but before we can test it out we need to do one more thing.
In order for the AI to know where to move, we need to add something called Nav Mesh Bounds Volume.
Inside the level, in the Place Actors tab, click on All Classes and filter for nav mesh bounds volume:
- X = -117
- Y = 0
- Z = 57
- X = 106
- Y = 11
- Z = 4

Connecting The Animation Blueprint With The Enemy Blueprint



To set the value of the Speed variable we are using the velocity of the enemy. We get a reference to the enemy by calling the Try Get Pawn Owner function which again, will return the owner of the animation Blueprint which in our case is the Parasite enemy.
The velocity of an Actor increases when the Actor is moving, and the VectorLength will return the length of the velocity which is a float number.
The faster the enemy moves, the higher the value is for the length of the velocity.
When we test the game now, we will see that the running animation is being played when the enemy is moving:
As long as the enemy is moving the running animation is being played, and when the enemy reached its destination e.g. PlayerCharacter, the enemy stopped and the idle animation started playing.
Detecting Collision Between The Enemy And The Player
The last step in our game is to kill the PlayerCharacter when the enemy reaches him.
To do this, we need to add a new Box Collision component to the enemy.
Inside the BP_Parasite_Enemy, in the Components tab click on the Add Component button and filter for Box Collision:

- X = 35
- Y = 32
- Z = 87

To detect collision in the code, we need to go inside the Event Graph, select the Collision Detection component and inside the Details tab scroll down to the Events settings and click on the green + button for the On Component Begin Overlap event:


The same explanation we gave when we first introduced the collision detection between actors also applies in this situation, so if you need to refresh your knowledge you can click here.
Before we test the game, I am going to select the enemy in the World Outliner and in the Details tab change the Wait Time value to 2 so that we don’t have to wait for 5 seconds before the enemy starts moving:

Now we can test the game:
27 thoughts on “Create A Parasite Platformer Game In Unreal Engine Part 10: Enemy AI Behaviour And Wrapping Up Our Game”
It was really helpful, and I enjoyied during following all of this tasts. Thanks!
Thank you so much for this! Great walkthrough of the entire process.
Great content, menus\items have changed\moved in 5.5. Might consider updating. Users may find some sections difficult to follow due to these changes
Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.com/zh-CN/register?ref=VDVEQ78S
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Kamagra Commander maintenant: Kamagra pharmacie en ligne – kamagra 100mg prix
Kamagra Commander maintenant Acheter Kamagra site fiable kamagra oral jelly
Tadalafil sans ordonnance en ligne: Pharmacie en ligne Cialis sans ordonnance – Cialis en ligne tadalmed.shop
Pharmacie sans ordonnance: pharmacie en ligne – vente de mГ©dicament en ligne pharmafst.com
kamagra oral jelly: Kamagra pharmacie en ligne – kamagra pas cher
Acheter Cialis 20 mg pas cher: Tadalafil 20 mg prix sans ordonnance – Tadalafil 20 mg prix en pharmacie tadalmed.shop
pharmacie en ligne livraison europe Livraison rapide pharmacie en ligne france pas cher pharmafst.shop
kamagra oral jelly: kamagra gel – Kamagra pharmacie en ligne
https://pharmafst.shop/# Achat mГ©dicament en ligne fiable
achat kamagra Kamagra Oral Jelly pas cher Kamagra Commander maintenant
kamagra oral jelly: acheter kamagra site fiable – achat kamagra
kamagra gel: kamagra oral jelly – kamagra pas cher
http://pharmafst.com/# Pharmacie sans ordonnance
Acheter Viagra Cialis sans ordonnance: Acheter Cialis 20 mg pas cher – Tadalafil 20 mg prix en pharmacie tadalmed.shop
acheter mГ©dicament en ligne sans ordonnance pharmacie en ligne france livraison internationale pharmacie en ligne sans ordonnance pharmafst.shop
Kamagra pharmacie en ligne: kamagra livraison 24h – Acheter Kamagra site fiable
Achat mГ©dicament en ligne fiable: Pharmacies en ligne certifiees – Pharmacie Internationale en ligne pharmafst.com
cialis generique: Achat Cialis en ligne fiable – Cialis sans ordonnance 24h tadalmed.shop
http://kamagraprix.com/# acheter kamagra site fiable
pharmacie en ligne france livraison belgique pharmacie en ligne Pharmacie en ligne livraison Europe pharmafst.shop
kamagra gel: Kamagra Commander maintenant – Kamagra Commander maintenant