Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In this video, we want to set up the BP enemy, which will be our last basic enemy.
It's going to have an aggro detection system, so if the player comes closer, it's going to start targeting
the player and also chase it.
And again, this is based on the BPM base which is based on the BP action chart base.
As always, let's start out by making the blueprint.
So on the content draw blueprints, characters, enemies.
Right click the BP enemy base and create Child Blueprint class and call this BP enemy AI and open it
up.
Click the sprite.
And here we just want to look for the I the fly I idle.
And again this only has an idle animation.
It doesn't have any other animations.
We don't have to worry about animation switching, and we can just make the capsule a little bit smaller
to better fit the shape, and also just move the sprite around a little bit here to center it.
And yes, this is good enough.
Now let's create the AI controller for this enemy.
So in the content draw blueprints AI.
And again based on the AIC base, create a Child Blueprint class and just called AIC underscore AI.
And open this up.
And on the event graph, we just want to do the same thing again.
We don't use beginplay.
We want to use the on possess just because it is safer.
We know there aren't going to be any timing issues.
And here we can just drag off the possessed pawn and cast to be enemy.
I.
And then we just save the reference and it's called owning I.
And we can move this up here.
And how do we get a reference to the player that we want to target?
Well, first let's just ignore the aggro system.
We're just going to forcefully get a reference to the player whenever the game starts or when we use
the on possess event.
And we can do this simply by right clicking and get player pawn, which is a shortcut that is an Unreal
engine.
And we can just get a reference to the player pawn and index zero is the player one, and we only have
one player, so we don't have to worry about the index.
And this we just want to save it in a variable.
So we can just promote the variable and just call it target pawn.
Like this.
And for now, let's just print string this to see that it works.
Print string and connect the target pawn.
Right.
And we have to use this AC enemy in the BP enemy.
Click the top level and type in I.
And as always for the AI controller class, just select the AIC and compile save.
And let's just check if this works well.
We first have to put it in the stage, not the AI controller, but the blueprint characters and the
enemies BP, enemy AI and just put it in the stage somewhere.
You can just drag it up here.
Like this.
And if we click on simulate, we actually have an issue because the player doesn't exist, so it doesn't
know what it's supposed to target.
But also you see that it just falls down.
So let's go to the enemy.
And also here for the character movement, we just want to look for a movement mode.
And select for default land movement mode, just select flying.
And again, I can simulate now.
And it's flying.
It's all fine.
And even if we start the game now with selected viewport, we don't see the message being printed.
And this is a timing issue that can happen in the IE controller.
And if we just use delay here, this delay 0.2 and this is just for testing.
But now this actually solves the problem.
And you can see we get the beep player zero.
And this is again with the timing because in this case event on process might happen before the player
is spawned in the map.
And we can just prevent this with the delay.
But in the end we're not going to use this.
This is a kind of dirty quick solution.
But for now, just to help us implement this, it is fine.
And we'll replace this with the aggro system later.
And now that we have a reference to our self and a reference to the target pawn on tick, we always
want to know which direction from us the player is located in and just fly towards that direction and
we can again use the look at rotation.
So find look at rotation and check from the eye, not from this eye controller, but check from the
owning eye and get actor location as the starting point.
And we want to look at the target.
So the target pawn.
And here we get actor location.
Like this and connect this here.
And again, we want to know the direction.
We don't care about the rotation.
We just want to get forward get forward vector.
And now we simply always have to move forward in this direction.
And it's always going to follow the player.
And just to demonstrate we can use the tick.
And here just print string.
And print the forward vector.
But actually we want to make sure that we have a target because if we despawn the player, it could
happen that we don't have a target.
And then we're going to get issues with the tick event here.
So here we first want to make sure that owning AI is valid.
Like this.
And we also want to make sure that the target pawn.
Is valid.
Because otherwise we're going to get an error message on tick if we don't have a target.
Like this.
And now let's just try it out.
Compile and save.
And you can see that if I move it's going to change the vector.
So this tells us that the AI is correctly tracking the player.
But now to actually implement this movement, we have to go to the enemy AI and implement a movement
function like we also did for the crab.
So in the event graph we just want to create a custom event.
And call it move towards.
And here we just use the add movement input again.
And this time we don't want to go forward.
We don't want to just go a set value on the X, but we actually want to get this value from the AIC,
right, to get the forward vector towards the enemy or towards the player, in this case the target.
So here we can just put this in here.
And it's going to create an input and the scale value.
We can also just connect it here.
And again one is going to make us go at full speed.
0.5 is going to make us go at half speed.
And I just want to set the default value for this so we can compile and save.
And for the scale value I just want to set the default value to 1.0, because this just makes sure if
you forget to fill it out, it's going to use 1.0.
So back in the AIC we can now get rid of this print string.
And here if it's valid we just want to actually get the owning I copy this paste this and then just
move towards the function which we just created and go here.
And then we just use this forward value and scale value.
We can just leave it at one.
You could implement a system where maybe it flies faster or slower at different times, different intervals.
But now yeah, just leave it at one and we can compile and save and check this out.
And you can see it is chasing me.
It is actually very scary.
It is very fast.
But I actually like this.
It's it's supposed to be a strong and imposing enemy.
And you can see even here it's going to try to get us, but it has a little bit too much health as you
can see as well.
So in the enemy here we just want to set the health actually on BBC vitality set the health to five.
In this case it's supposed to be a bit stronger but ten is a little bit too strong.
And we can also adjust the speed a little bit.
So I can tell you how this works, because on the character movement component, this time around,
we actually don't want to use max walk speed.
We actually want to use the fly speed.
So here you see the max fly speed.
And let's just set this to 400.
And this is how you can apply the flying speed.
Let's check this out.
And the 400 is still 600 is actually.
Yeah, a little bit too crazy because it would be exactly as fast as our player.
So 400 gives us a little bit more leeway.
It is still imposing.
It is still strong.
Before we get into the aggro system I just want to change the direction because now the AI is always
looking to the right, even if the player's on the left of it.
So we just want to implement this quickly in the BP enemy.
We can now go to the move towards event and after the add movement input, we just want to set actor
rotation.
And here again we can use our good old friend select Utility Select and we can then decide if we pick
option one or option zero depending on an input.
And while everything we have to check here is from the world direction we can break.
And we only need the X because again, if the x is negative, because again, if the x is negative,
the AI is going to want to move to the left side because the players on the left side.
And if the X is positive, it's going to want to move to the right side.
And we can simply use this again with a smaller check.
Just check for less and use the result here as the index.
And if this is true, this means that we want to go left so we can just set the actor rotation to 180.
And if this is false, we just want to look right so we don't have to change anything.
Just leave it at the zero.
And this is actually how easy it is.
Just try it out and look at this.
I want the left side.
It's looking left.
I'm on the right side.
It's looking right.
And I'm actually getting hammered by all of these enemies now.
But this is how it works.
As the last thing for this enemy, we want to actually set up the aggro system.
So in the AC instead of on beginplay with the delay, just getting the target pawn and setting it here.
We just want to get rid of this, and we just want to create a small custom event here.
So just right click Custom event and just set and just set target player.
And here we just want to get the target pawn.
Set it.
Here and just connect this.
And this is just a very simple function we can use.
In the BP nmai.
We now want to go to the viewport and while the capsule component is selected, add another thing.
So here we want to look for collision again.
And in this case a sphere collision is actually the best right.
You cannot really see it now.
But we just want to call it aggro range.
And then here on the right side click away here.
And we just want to make the sphere radius bigger.
And it might be a little bit hard to judge here how big it should be.
So we can just kind of look back at the map like this.
And I think it should be a little bit bigger.
So around 500.
And here it looks really big, but in the map you can see it is not that huge.
And if the player steps into this range, we want to make the AI aggressive and start attacking the
player.
Of course we have to set up the collision again.
So on the aggro range to the right side.
Scroll down and just make it custom.
Ignore everything and just look for the pawn.
Then scroll down to the on component Begin overlap event like this.
And as we've done many times other actor cast to be player.
Like this.
And now we just want to set the target player.
But the set target player function is actually not available here because it is on the eye controller.
We first have to get a reference to the eye controller.
So here we can just get eye controller.
And this is again a built in function.
And for the controlled actor we just pass self.
Like this.
But even this doesn't let us call the set target player because we need to cast it to the AIC.
So here we can cast to AIC.
I.
And connect here.
And now we can call set target player.
Just like this.
And then the target pawn is whoever is the overlapping BP player can just plug it in here.
Double click to reroute it.
And just like this.
Mhm.
So now, if you want to cast to the AI controller here or on Beginplay and save it, it kind of depends
on if you want to use it multiple times.
So it's better practice to just do it once here and save it in a variable.
But actually the aggro range is only going to be active a single time because after we go through all
of this, after we set the target player, we actually don't want to use this collision anymore.
We can just turn it off.
And this is never going to fire a second time.
But for now, let's just check this out, see if it works and it's too close.
Now, I can't really test this, so just move it over to the side.
Right.
So I'm standing here.
It's not coming from me.
It's not attacking me.
I walk to the right and I enter the aggro range, and it's going to come from me and going to start
chasing me.
So this is working fine.
Now, this is just a small thing.
And like I said before, we just want to make sure that this can only be triggered a single time.
So after the cast to BP player, I can just open up some space here and simply add a do once node the
top one and never reset it, right?
So this way we make sure that this is never active again.
And now we're done creating four different unique enemy types.
And I hope this taught you a lot about AI and how it isn't that complicated, and how you don't actually
need to use behavior trees.
In the next section, we're going to start looking into the user interface to show our health.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.