Full transcript
Outcome of This Part
0:00[Music]
0:05welcome back everyone to part 13 of our
0:08smarts enemy AI series and in this part
0:10I'm doing something uh quite new and
0:12exciting uh which is I'm going to be
0:15creating a new Mage enemy uh from
0:17scratch so we won't be using the um uh
0:21mannequin from Unreal Engine we will be
0:23using um this custom mesh from mixo as
0:28well as custom animations and everything
0:30uh to show you how to create a
0:32completely new enemy from scratch with
0:34the animation blueprint and all um now
0:37this uh Mage enemy is going to have a
0:41Teleport function like this teleport
0:45attack this is the same attack that the
0:46player has uh and then uh we'll be
0:49moving around the player I can show you
0:51in slow motion yeah like that teleport
0:55and if uh I get the health of the enemy
0:58low enough uh the enemy can also heal
1:00like
1:01this and after they're done healing they
1:04go back to their teleport and attack
1:06sequence
1:08perfect so let's get
Animations & Model From Mixamo
1:12started all right so to start with a um
1:16a character from scratch the first thing
1:17we need to do is have a mesh uh and some
1:21animations and I will be using uh
1:23mio.com to get both the character and
1:27the animations uh I'm using this
1:29character called katuin or something
1:32like that um doesn't really look like a
1:34mage but I think I'll make it work and
1:37the animations that I'll need are uh
1:40from this guy so this is the Mage guy of
1:43mixim uh and I'm using a lot of
1:45animations so there's uh the walking
1:47animations and the running animations in
1:49all directions so walk forward backwards
1:51left and right uh and run the same and
1:55then there's an attack animation a hit
1:57reaction and a jump I'm going to leave
1:59um all of the names of all the
2:00animations that I'm using down in the
2:02description uh and of course um you'll
2:04be able to download um all of the
2:06project file and assets from my
2:09patreon um I've already uh downloaded
2:13all of these and I have them here in my
2:15content folder under characters Mage uh
2:19I have uh the mesh so this is the uh
2:23mesh that's you saw in
2:25mixl and uh here are all of the
2:28animations that I mentioned
2:31um and of course I'm going to show you
2:33when we're going to use each one we're
2:34going to be creating some montages out
2:36of them as well so we're going to go
2:37over most of them uh the one thing that
2:40I did create as well out of all these
2:41animations is a blend space so this is
2:45just the uh Locomotion blend space um
2:49and I'm not going to go over how to
2:51create a blend space as always there are
2:52a ton of tutorials on how to do that and
2:54it's very basic so it's just the
2:57direction that the character is looking
2:58and the speed that they're moving moving
3:00at um all right so now that we have our
3:05uh character uh ready and our animations
Creating the Mage Enemy BP
3:09uh the first thing we need to do is to
3:11actually create the enemy so in our
3:13enemies folder uh right click on the
3:15base and we're going to create a new
3:17child uh let's call this uh BP enemy
3:23Mage and open that up and we're going to
3:27just dock it back here and let's replace
3:30the mesh with our Mage mesh so going to
3:34go over here and yeah the skm Mage now I
3:39did notice that the model from mixim uh
3:42is quite big so if you compare the size
3:44you see that the mixo model is
3:47significantly larger than the um uh the
3:50mannequin so I'm going to just scale her
3:52down a bit to
3:540.85 on all
3:56axes right now she's uh fitting with
3:59within the capsule and will be the same
4:01size at the rest of the
4:03enemies all right um and now that we
4:08have our um uh enemy uh mesh uh attached
4:13to this uh actor we can actually put it
4:16in the world uh but nothing will happen
4:18uh because yeah we don't have an
4:20animation blueprint Behavior tree
4:22there's still a lot we have to do of
4:24course um so first thing I want to do is
4:26actually create the animation blueprint
4:28uh and this was a request from a lot of
4:30people that uh don't want to use the
4:32mannequin blueprint so I'm going to show
4:33you what goes into creating a custom
4:36anim blueprint that works with our enemy
4:39AI um so let's go over to our characters
Creating the Mage Animation BP
4:44our Mage
4:45animations and right click here I'm
4:47going to search for
4:50animation
4:52blueprint and it's going to ask me which
4:54skeleton I'm going to say the SK Mage
4:56skeleton and I'm just going to call this
4:58ABP
5:01Mage and let's open it
5:04up all right so first thing we need to
5:06do is we need to have a um a new state
5:11machine so I'm going to search for State
5:13machine and I'm going to call this the
5:16um
5:19Locomotion well and I added a slash
5:22there by accident and we also need a
5:25default slot so search for default slot
5:28uh this is what allows us to play
5:29montages without this montages won't
5:32won't
5:33play um and then let's open up our
5:36double click on our Locomotion
5:38States so here we're going to add a
5:41state we're going to call this um base
5:45loc
5:47motion and uh we're going to have a
5:50we're going to have only two states a
5:51base Locomotion and a jump state so I'm
5:54going to also add a state here and call
5:56it
5:57jump and there's a transition from
6:00Locomotion to jump and backwards uh
6:02we're going to go over these transitions
6:03in a bit uh but let's first double click
6:07inside our base Locomotion and add the
6:09animation now the animation is going to
6:11be the blend space so this uh blend
6:14space that I created from The Walk and
6:16Run
6:17animations um blend space requires
6:20direction and speed and we need to go
6:23into our event graph here and um get
6:27these uh variables or assign these
6:29variables now I'm I can also just copy
6:32it so in our ABP Manu we already did
6:36this so I'm going to copy here in the
6:39event graph uh we need the direction and
6:43we need the um is falling we're going to
6:45use this actually for the jump State and
6:48we need the ground speed so I'm going to
6:52copy this
6:53part um I'm going to copy this part cuz
6:56we use the movement component to get the
6:58ground speed
7:00I'm going to copy the direction part and
7:03oh we said is falling as well okay so
7:05I'm just going to copy all of these head
7:08back to my Mage uh create a sequence by
7:12pressing s on the keyboard and click or
7:14of course right click and search for
7:16sequence and I'm going to paste here
7:18everything that we
7:21have all right so let's plug
7:25in this let's plug in this here
7:32and we need a third pin for the
7:36Direction all right now you'll see some
7:38nodes are gray because we don't have a
7:40variable for them you can just um right
7:42click and say create variable for all of
7:46these set variable nodes create variable
7:48create variable Direction create
7:51variable create variable now if I
7:54compile uh still have a few
7:57errors um
8:00this also needs a create variable great
8:03okay now no errors just to warnings for
8:05the transitions that we missing but
8:06we're going to add these uh in a
8:08bit all right so now we have uh
8:11variables for the ground speed velocity
8:13direction and is falling so back to our
8:18um Locomotion State we can now set the
8:23direction and the ground
8:27speed excellent
8:30all right um and for the jump State um
8:34I'm I just have one jump animation so
8:36I'm going to search here for mage
8:39jump uh proper Locomotion you should
8:42have a jump uh start a jump Loop and a
8:45jump land or jump finish um but for the
8:48sake of this tutorial I'm just going to
8:50have one jump animation it's going to
8:52look a bit weird in some cases but um
8:55again it's not an animation
8:57tutorial um all right and I'm going to
9:00make sure that the jump is looping by
9:02the
9:04way and now to our transitions so going
9:08from base Locomotion to jump the only
9:10check we need is is falling so if the
9:13character is falling then go to the jump
9:15State and jump back to base Locomotion
9:19just the opposite of that so is not and
9:23search for not
9:25Boolean is not
9:28falling
9:30all
9:32right and that's pretty much it for our
9:35um animation blueprints it's really
9:37basic uh but this is all we need we can
9:39play montages we have our Locomotion
9:42State and we can
9:43jump perfect now back in our BP enemy
9:48Mage let's assign our animation
9:51blueprint here so instead of ABP Manny
9:53let's search for ABP
9:55Mage and right there she starts to move
9:59and be animated and over here in the
10:01world it's the
10:04same um great so before we start seeing
Setting Mage Specific Variables/Functions/Montage
10:08this mage character move and do some
10:10things there are a few
10:13um um functions and variables that we
10:15have to override um and clicking on
10:18interface here I'm going to start with
10:22get where is it the set movement speeds
10:26this one so this sets the movement speed
10:28based on this um enum if you remember so
10:32I can pull off the enum and say
10:34select and plug the output value here so
10:37it knows it's a
10:39float um and we can say what are the
10:42speeds of this Mage enemy uh an idle
10:45it's always zero walking I'm going to
10:47say like 150 jogging is about 250 and
10:50sprinting is about
10:52400 now these variables are actually
10:54based on my Locomotion um they're not
10:57exactly perfect um but you can uh keep
11:00playing around based on your animations
11:01and how you want it to
11:04look um all right so that's the set
11:07movement speed and the second thing is
11:09the um get idle range so if you recall
11:13we have an attack radius and a defend
11:15radius for each enemy uh and here I'm
11:17going to say for the Mage the Mage I
11:19wanted to attack from um a a far away
11:23distance so let's say 500 and when it's
11:25not attacking I want it to go even
11:27further so it's harder for the player to
11:29hit so I'm going to say 700 that's our
11:32attack and defend
11:35radius and um if you click on the uh
11:41actor uh the root component itself then
11:44you can start setting some of the
11:46variables now the first and most
11:47important variable is our Behavior tree
11:50we haven't created the behavior tree for
11:52the Mage yet but I'm just going to use
11:53the ranged Behavior tree for
11:57now and we also need need a hit reaction
12:00montage and um yeah just I think that's
12:04the only things we need for now the
12:05behavior tree and the hit reaction
12:07Montage uh we don't actually have the
12:10hit reaction Montage yet so let's create
12:13it um so in our animations I have a hit
12:18reaction this hit reaction uh
12:22animation um and uh again the link for
12:25it or the name of the animation that I
12:27got from miimo is down in the
12:28description
12:29and to create a montage I'm just going
12:30to rightclick and say create anim
12:35montage and I'm going to call it
12:38Montage uncore Mage hit
12:42reaction I'm going to create a new
12:44folder call it montages just to have
12:47things a bit cleaner and put it
12:49there all right so we have this hitch
12:52reaction
12:53montage and back here I can select it
12:57and it's right here Montage Mage hit
13:01reaction awesome so now let's start to
13:06see um if this Mage will um have any
13:12Behavior to
13:13it nice so you can see her moving around
13:17uh obviously she's uh not going to be
13:19able to attack because she doesn't have
13:21an attack event so right now she tried
13:23to attack and she is Frozen in place uh
13:27if I attack her
13:29and she does the hit reaction montage
13:31and then moves
13:33away and she's just going to keep
13:35strafing around me and not being able to
13:40attack all right
13:43so now that we have um somewhat of a
13:48working uh enemy let's start adding Mage
13:51specific functionality to her uh and I'm
Creating the Mage Attack Functionality
13:54going to start with the attack uh
13:56function I'm going to give her I'm going
13:58to make her main attack to be the same
14:00as uh the player so this uh this like
14:03haduken or whatever uh throwing a magic
14:06ball
14:07spell and I have the animation for it
14:10which is the same one the player is
14:12using uh where is it yeah this one it's
14:15called
14:17Fireball um so we want to create a
14:19montage out of this uh but you'll notice
14:22that it has a very long windup time so
14:25all of this time character is not doing
14:26anything and only about here does the
14:28character start to make the Fireball and
14:32then it
14:33shoots um so I'm going to make the
14:35Montage start from somewhere around here
14:38but let's let's see how we can do that
14:40so on the fireball animation right click
14:43create anim montage and call this
14:46Montage
14:48Mage um Fireball why not I mean it's not
14:51really a fireball but it's
14:54uh some sort of
14:57ball and we're going to open up our
15:00montage and to make it start at a
15:02specific point I'm going to find the
15:04point I want let's say yeah somewhere
15:06around here 1 1.03 and I can click on
15:11the animation here this one and on the
15:13start time I'm going to say starts at
15:181.03 great so now my Montage starts
15:22here if we wanted to have a longer
15:24windup time we can say h start at 0.8
15:27for example
15:29yeah whatever we
15:31want and somewhere about here we want to
15:36add a notify and right click add notify
15:40Montage notify and call it uh fire this
15:44is when we will actually fire the
15:47ball yeah I think about here is
15:51fine all right so we have our Montage
15:55ready let's create the attack event now
15:58back back here in our BP enemy Mage if
16:01you recall we have attack end Attack
16:03start and so on the attack end and
16:05attack start uh just as a reminder are
16:08in the um base enemy so this is the uh
16:13where is it uh this is the attack end
16:16where it uh puts back the stores the
16:18tokens again and calls attack ended and
16:21the attack start is actually a
16:24function Attack start uh which reserves
16:27a token does all things for the group
16:29enemy uh combat so we're not going to
16:31override this we're only going to
16:33override the
16:35attack so uh how are we going to do this
16:38let's go to our BP enemy Mage and you
16:41can just double click on the attack or
16:43right click search for event attack
16:45whatever you want I'm going to double
16:47click on
16:48it and first thing we need to do is uh
16:52play the Montage so I'm going to pull
16:55off here and say play montage select
16:58this one the one that takes a skeletal
17:00mesh because this one has all the output
17:03pins that we
17:04want and the skeletal mesh will be I'm
17:07going to pull off of our mesh here the
17:09Montage will be the Mage
17:13Fireball and
17:16um we need to pull off of the notify at
17:19the point where we uh get the fire so
17:22switch search for switch make sure it's
17:25not plugged here but plugged into on
17:27notify begin
17:28so un notify begin we're going to switch
17:31on the name fire this is what we created
17:34we don't need a default pin so I'm going
17:35to uncheck this and on fire we want to
17:40fire the uh like this magic spell that
17:43we have and again if you recall in our
17:45bpc attacks I'm going to right click
17:47here this is our attacks actor component
17:50uh we have this magic spell and this is
17:53the one that the player is using and the
17:55nice thing about using uh actor
17:57components to house all of our attacks
17:59is that we can reuse the same spell that
18:01the player is using for the enemy as
18:03well so back in our enemy all I'm going
18:05to do is pull off of bpc attacks and say
18:09magic
18:11spell great now we just have to plug in
18:15um all of the variables that this
18:17needs so for the spawn transform um I'm
18:21going to right click and split we only
18:22need the spawn location because the
18:24rotation and scale will be um based on
18:27the target cuz we do have a Target
18:30here um and the target of course is just
18:32our attack Target so I can just plug
18:34this here to our attack
18:36Target and make it a bit
18:38cleaner now our spawn location is where
18:42the hands of our mesh is so uh I need to
18:46know the name of the socket of the hand
18:47so I'm going to click on the mesh open
18:49up the skeletal
18:51mesh and I think it's just called
18:54hand yeah right hand so I'm going to use
18:57right hand or left hand as matter let's
18:58use right
19:00hand um so to do that we're going to get
19:03our
19:04mesh uh get socket
19:09location so this gets the world location
19:11of a socket and the socket is called
19:14right hand now it's going to be a socket
19:16or a bone they're both the same in this
19:19case all right
19:22so then we
19:24have an attack function
19:29uh do we need anything else oh very
19:31important we whenever you call attack
19:34you need to call attack end uh if you
19:37recall again for all of our characters
19:39when we call attack where is attack
19:43after the attack is over we have to call
19:45attack end this is very important
19:47otherwise we'll get stuck in the attack
19:49um Behavior tree
19:52task so back here in our Mage on
19:56completed I'm going to call attack end
19:58and attack end is a function already in
20:00the um enemy base so we don't need to do
20:04anything else and I'm going to call it
20:06uncompleted and uninterrupted making
20:08sure I pass the attack
20:13Target all
20:15right
20:16um do I need anything
20:19else well let's see if this works I'm
20:21going to
20:22play and I did nice I got attacked oh
20:28but we forgot to add how much uh the
20:30damage info so I'm actually not getting
20:32damaged I forgot the damage info here so
20:35pull off of damage info and say
20:38make and let's say damage 20 or
20:42something like that damage type
20:44projectile doesn't matter and I'm going
20:48to leave um well we don't really use
20:50these from our damage system so they
20:52don't matter the only thing that we use
20:53right now is amount we actually use can
20:57be blocked or not but but the player
20:58can't block for now so also doesn't
21:01matter now I should be getting
21:04damaged and Boom o yes I am getting
21:07damaged quite a
21:09lot great and I can also damage
21:16her um you know the the hit reaction is
21:18a bit slow you know it's like when she
21:20gets hit she was like yeah it's a bit
21:23slow so I'm going to speed it up a bit
21:26now there's a few ways we can speed it
21:27up the simplest is just to go to the
21:32um Montage hit reaction click on the
21:35animation here in the timeline and say
21:38play rate
21:401.25 instead of one so now it's a bit
21:45faster yeah that's a bit better let's
21:47make it even
21:501.4 yeah that's better so now if I
21:53attack her boom yeah
21:56nice great
Creating the Teleport Ability
22:00now the next thing uh I want to do is
22:02actually add an ability to our Mage and
22:05this ability will be a teleport ability
22:09uh to allow the mage character to sort
22:11of quickly move from one location to
22:13another and uh before I start building
22:17that I'm going to be using some uh I
22:19want to be I want to show you what the
22:21uh visual effects that I'm going to be
22:23using for this teleport and I'm going to
22:24be using uh the Paragon Gideon assets
22:27from the real Marketplace which is free
22:29to use uh and I'm going to be using
22:31mainly uh two um assets from that and
22:36we're already using by the way the
22:38Paragon Gideon for this Fireball or this
22:40haduken spell um and I'm adding uh let
22:44me show you who I'll be using so Paragon
22:47Gideon here I've already downloaded them
22:49or I added them to the project particles
22:52Gideon abilities these two burden and
22:56meteor so inside meteor here we have
22:58this meteor trail and I can show you
23:00what it looks like in the world so this
23:03meteor Trail
23:04here um reset emitter so when it moves
23:08it looks like this and this is going to
23:11be our teleport effect so once the mage
23:14character moves this will be the trail
23:16it leaves behind when it teleports and
23:19the other one
23:20burden
23:22um yeah this one uh I will hide the body
23:27of the Mage when the Mage teleports uh
23:30and replace it with this so it looks
23:32like it's turned into this uh uh Magic
23:35Ball and leaves a trail behind it when
23:37it moves um so I think it's going to
23:41look pretty cool when it's all put
23:42together and you're going to see that in
23:43a
23:44bit all right so now that I've showed
23:47you the two assets that we're going to
23:48use uh let me explain how I'm going to
23:50create the teleport uh functionality
23:53itself so over here in our enemy um I'm
23:57going to create a new custom event and
24:00call it um
24:02teleport yeah just call it teleport now
24:05a lot of people will do a teleport uh
24:08just by changing the actor location so I
24:11can uh this teleport will take a
24:13location
24:15parameter uh
24:17location which will be a vector and a
24:20lot of people will just say uh set actor
24:23location to be the new location now this
24:27is the simplest way to do a teleport uh
24:29but the problem is this actually takes
24:32the actor from one place and puts them
24:34immediately to another place I actually
24:36want the teleport to uh move the
24:39character so you see the trail behind
24:41them uh but I just want them to move at
24:43very very high speeds so it looks like
24:45they're teleporting um and to do that uh
24:48we're going to have to uh get a bit
24:50creative with the teleport instead of
24:52just setting actor location if you don't
24:54want a trail effect if you want the
24:55teleport to be instant and all that then
24:58this is enough for a Teleport
25:01functionality uh but let me show you
25:03what I want to
25:05do so first thing we need to do is uh
25:08well I'm since I'm going to be moving
25:09the character normally we're going to
25:10just use the AI move to
25:13node uh and the pawn here will just be a
25:17reference to
25:18self and the destination will be this
25:21location and acceptance Radiance let's
25:23put something like 15 this is how close
25:26to the location uh should be before it
25:29stops now if I do this then it's not
25:31really a Teleport then the character is
25:33just moving to that location at their
25:34normal speed but I want them to have a
25:37very very high speed now I can just
25:39modify the movement speed uh but there
25:42would still be problems uh because uh no
25:45matter how fast the character will be
25:46moving there's still like ground
25:48friction and so on so you have to modify
25:50all these variables so instead of doing
25:52that uh I'm going to make the
25:55character's movement mode flying and
25:58when they're flying then uh they are not
26:01subject to
26:02friction so I'm going to pull off of the
26:05uh character movement component here and
26:08say Set uh movement
26:11mode set movement mode and I'm going to
26:14make it
26:15flying and let's move this a bit far
26:18away because we're going to do a lot of
26:20things before actually
26:22moving um and the next thing we want to
26:24do is make the flying speed very fast so
26:28Set Max Fly speed um I don't know
26:31something like uh
26:355,000 um and there's another variable
26:39that we have to set off of the character
26:42character movement as well which is um
26:45max
26:48acceleration uh I don't think there is
26:50flying acceleration and regular
26:51acceleration just
26:53yeah acceleration in general and that I
26:57want want to be the highest number
26:59possible so because I don't want there
27:01to be acceleration time I want when
27:03teleport happens the character to
27:04already start at Max Speed so I'm going
27:06to just do a bunch of nines
27:09here uh and don't worry we're going to
27:11reset all this back when the teleport
27:14ends all right so now we set the
27:17character to flying at very high speeds
27:20and before we move to we want to also
27:23hide the character mesh so we said we're
27:26going to set visibility
27:29uh new visibility is unchecked that
27:31means not visible and propagate to
27:34Children if you check this that means
27:36that also the health bar because the
27:37health bar is a child of the mesh then
27:39the health bar will also be hidden and I
27:41do want that because uh I don't want you
27:44to see a teleporting health bar so I'm
27:47going to check this as
27:49well um and one thing also when the
27:53character is teleporting I don't want
27:55them to be able to collide with other
27:56pawns I I want them to pass through
27:59other pawns as if they don't have any
28:01Collision so to do that I'm going to set
28:04the uh Collision profile what was it uh
28:08no
28:10Collision
28:11U set
28:14Collision response to channel yeah set
28:17Collision response to channel and the
28:20pawn channel is going to be uh ignore so
28:23if you uh collide with the pawn just go
28:26through it
28:27uh that way it actually looks like
28:29they're uh they don't have uh weight and
28:32they're going through other players and
28:35enemies and uh finally before actually
28:38moving uh we need to spawn these um
28:42effects the trail effect uh and the um
28:45the body effect that we have so uh since
28:49these are Legacy particle effects I'm
28:51going to use uh spawn emitter attached
28:54and I'm going to attach it to the mesh
28:57uh if if you're using Niagara then don't
28:59use spawn emitter if you're using
29:00Niagara effect say spawn uh what was it
29:03system so spawn system is uh what uses
29:06Niagara effects I don't have any Niagara
29:08effects uh so I'm going to use spawn
29:12emitter and uh here I want what was it
29:15called uh burden that was the first one
29:18yeah burden dot that's the one we want
29:21and I want to attach it to the spine of
29:23the mesh uh I think it's just called
29:25spine one but let's validate that spine
29:29yeah just spine one so around the roots
29:32of the
29:32mesh and the attached point is spine
29:37one great uh I'm going to promote that
29:40to a variable because we have to get a
29:42reference to it to be able to delete it
29:43later on so I'm going to call it the
29:47teleport body
29:51effect and um we need another spawn
29:55emitter attached as well so I'm going
29:57going to just copy and paste
30:00this and this time it's called the trail
30:04yeah metor Trail and I'm going to spawn
30:07it attach it to the spine as well oh I
30:09forgot the attached component that
30:11should be the
30:12mesh we're of course attaching it to the
30:15mesh let's not forget that very
30:17important and uh even though the mesh is
30:20invisible you can still attach things to
30:22it that's
30:23fine um and I'm also going to promote
30:26this to a variable call it the teleport
30:29Trail
30:32effect
30:34uh anything else before moving to I
30:38think that's it for
30:40now
30:42um let me move this a bit here so it's
30:49cleaner
30:51and they have to be in the same line
30:54okay
30:56um perfect so I think this will work um
31:01but now we need to have a Teleport end
31:04so what happens when uh the teleport is
31:07finished so I'm going to create a new
31:10custom event here call it teleport end
31:15and I'm just going to call this teleport
31:17end here on
31:19success and actually on fail as
31:23well
31:25um all right so teleport end what does
31:28it do we have to reset everything back
31:30so getting our character movement
31:32getting our movement speeds uh fly speed
31:34all of that I'm just copying all of
31:37these the Collision profile yeah we need
31:40all of this so I'm going to copy this
31:42paste it
31:44here and set new variable so movement
31:47speed back to walking that's the default
31:49movement Speed Max Fly speeds I don't
31:53think we're going to use it anyway so we
31:54don't have to reset it to anything
31:56because uh this character doesn't fly in
31:59any other point so I'm just going to
32:00delete it keep it at 5,000 that's
32:04fine um max acceleration I'm going to
32:07click on the character movement to see
32:10what Max acceleration default is 1,500
32:14all right so I'm going to default that
32:16back to
32:171,500 would be nice to create a variable
32:19out of this as well but it's fine for
32:21now and the mesh visibility is visible
32:25so check this and the response to the
32:28pawn channnel is block cuz that's a
32:31default
32:32oh actually this is not correct uh we
32:35shouldn't the mesh already has uh the
32:39pawn channel on ignore the mesh doesn't
32:41have collision with Pawn anyway The
32:44Capsule that's what collides with the
32:45pawn so you see here this is what we
32:47need to disable Collision for the
32:50capsule not the
32:53mesh all right so capsule
32:58Pawn back to
33:00block all
33:03right um anything else oh we need to
33:06destroy this and that um so I'm going to
33:09create a sequence node here by pressing
33:12s on the keyboard and click and I'm
33:15going to get my
33:17teleport and right click on it and say
33:20convert to validated get uh this makes
33:23makes sure that it's valid before doing
33:24anything because uh maybe the
33:27effect ended already so it wouldn't be
33:29valid so if it is valid I'm just going
33:31to say destroy
33:33component and the reason I did a
33:35sequence is because I want to do it for
33:37the trail effect as well so get right
33:41click convert to validated
33:45get and if it is valid destroy
33:50component now with a sequence even if
33:53this is not valid it will still go to
33:55the second one if I had them on the same
33:57line that I have to check is valid go
33:59here and so on so this is just a bit
34:02cleaner
34:04um but before doing that
34:08so actually not when the enemy reaches
34:13um the point do I want to destroy these
34:16immediately I want the trail to stay
34:18there for maybe like half a
34:21second uh after reaching the
34:25uh uh the location so I'm going to add a
34:28delay about half a second and then
34:31destroy
34:33these uh oh and we also need to add a
34:37event dispatcher so on on event
34:39dispatchers here I'm going to add an
34:42event call it on
34:45teleport uh end and we're going to call
34:48it here so I'm going to pull off and say
34:51call uh right before the delay uh we'll
34:54be using this in our Behavior treat task
34:57to know when the teleport is
35:01ended uh anything
35:05else okay so this looks like it's good
35:08for now um now we need to try it out uh
35:12this is the exciting part so if you
35:15recall we are still using the behavior
35:17tree for the ranged enemy uh so I'm
35:19going to open up the behavior tree for
35:21the ranged enemy and I'm going to add a
35:23new task uh off of BTT blueprint base
35:28put it in the tasks folder and call it
35:31BTT uncore Mage
35:37teleport and as always uh rightclick
35:41event receive execute Ai and don't
35:45forget the Finish
35:49execute uh what this does is it will um
35:52take a location and the location will be
35:56uh at a variable here call it teleport
35:59location and it will be a Blackboard key
36:02selector make sure to click the IE icon
36:05to make it um editable from the
36:08Blackboard uh sorry from the behavior
36:10tree and we're going to pull off of the
36:12pawn and cast to our Mage enemy and
36:16that's why I named this btor Mage to
36:19make sure we don't use it in any other
36:21enemy type it's only going to be used
36:23for the Mage and we are just going to
36:26call tele
36:27port and pass in our location which we
36:32get this one and say get Blackboard
36:35value as Vector because we know the
36:38location is a
36:41vector um all right and uh now we want
36:46to pull off of this and assign on
36:51teleport end so we are binding to the
36:54teleport end event and say
36:57um on teleport
37:01ends what we want to do is finish
37:04execute with success
37:07true oh and if the cast fails just
37:10finish execute with success
37:13false
37:15um anything
37:18else oh actually one important thing
37:20that um I forgot to do in a few other uh
37:25events as well but a few other Behavior
37:27tree tasks but it wasn't a problem it's
37:28going to be a problem if we don't do
37:29this now which is we bind to an event
37:33but we never unbind it's really
37:34important to unbind once you've done
37:36what you wanted to do so let me show you
37:38why or how first of all um you just pull
37:41off of the um Mage enemy and say uh
37:46unbind teleport end unbind event from
37:49teleport end not all events just a
37:51specific event and the specific event is
37:54this one and I'm going to call it here
37:57so this means as soon as teleport end is
38:01called um and I'm already buy I'm
38:04already bound to it then unbind to it
38:06the reason is if teleport is called
38:09twice while teleport is still
38:11active um then this bind uh will trigger
38:17even if you're not in the behavior tree
38:18task because you bind to it and you
38:20never unbind that means no matter when
38:23uh teleport end is called this will
38:25still execute so that means that finish
38:27execute can be called at a time where we
38:29don't want it so we have to make sure
38:31that when you bind to something and what
38:32you already wanted to check uh happened
38:35the event happened then unbind from
38:37it and we're going to be using this
38:39again later on I'm going to show you
38:42how
38:44um yeah I think that's it for this
38:47Behavior tree task let's start using it
38:49instead of
38:52um yeah maybe in this Branch when we're
38:55out of uh line of sight instead of a
38:58regular move to I'm going
39:00to do a
39:04Teleport and the teleport location will
39:07be the point of interest because this is
39:09what the eqs stores its value
39:12in so right now if everything works
39:14correctly um when I move out of line of
39:18sight the Mage enemy should teleport to
39:22me there we
39:25go all right so it's teleporting but
39:28it's
39:30uh what was
39:33that it's doing some weird
39:38things um so one of the weird behaviors
Fixing Issues With the Teleport Ability
39:42I can already
39:43tell uh is because when the teleport uh
39:46when the enemy reaches its final
39:47destination it still has momentum so it
39:50keeps going uh what we want to do is to
39:53stop the enemy uh from moving
39:55immediately
39:57so on teleport end before anything
40:01else uh what we want to do is let me
40:05pull off of this
40:09here uh what we want to do is call
40:14stop movement immediately so that the
40:17character doesn't keep moving once they
40:19reach their
40:22destination um this should improve
40:24things a bit but won't fix all the
40:26problems yet uh one of the problems I
40:29think I know what it is as well but
40:32let's just see what this will
40:34do all right move out of line of
40:38sight see now the teleport is to a
40:42controlled location it doesn't zo across
40:45the screen
40:46anymore and this is the second thing
40:49that the enemy can teleport multiple
40:52times and keep teleporting around
40:54itself um and the third problem is the
40:57enemy can hit itself so we're going to
40:59fix both of both of
41:01these so the first uh problem about
41:04teleporting multiple times uh we're
41:06going to fix by adding a new variable
41:10here called is teleporting so I'm going
41:12to create this variable call it is
41:17teleporting and uh that's going to be a
41:20Boolean and as soon as we start
41:22teleporting I'm going to set this value
41:24to true and when we're done teleporting
41:28after this delay here I'm going to set
41:30this value back to
41:32false is teleporting is false so now we
41:36know when we are currently in the middle
41:38of a Teleport so before actually well as
41:42soon as we call the teleport I'm going
41:44to do a branch and I'm going to
41:46check uh if we are not
41:52teleporting then uh proceed to uh set
41:56teleporting to true and do the teleport
41:59but if we are teleporting then we want
42:01to do nothing um but one important thing
42:04that we don't we shouldn't forget is
42:06that um this uh event is called from a
42:09behavior tree task so if we call
42:12teleport and we're already teleporting
42:15we still need to call on teleport end so
42:17that this uh execute finish execute
42:20happens otherwise we'll be stuck in this
42:23uh task and nothing will um uh and we
42:25won't be able to get out of it so we
42:27need to also call uh the on teleport end
42:32here uh the uh event dispatcher not the
42:36event itself just the event dispatcher
42:38on teleport end because the event does a
42:40whole bunch of other things that uh un
42:42undoes all of the changes we made to the
42:44character movement but we didn't even do
42:46these changes yet so we just need to
42:48call the event
42:49dispatcher uh one quick thing to note
42:52here is that this won't work um and let
42:55me explain why so as soon as we call
42:57teleport uh and the branch and if we're
42:59already teleporting then this Branch
43:01will immediately go to the false and
43:03dispatch the event this will all happen
43:05in the same tick that means that the
43:08task here we call teleport first so
43:12teleport is called branch is false then
43:15the event is dispatched all of this will
43:17happen before this node moves to the
43:19next one so before we even bind uh that
43:23means that we will bind after the event
43:25has already been dispatched so to fix
43:27this we can move the teleport to be
43:30after binding so we bind first and then
43:32call teleport or the safer Choice uh so
43:36that the position of the bind doesn't
43:38really matter the safer choice is to add
43:41a delay until next tick so I'm going to
43:43right click here search for delay till
43:46next tick and what this does is that it
43:50waits for one complete tick um and then
43:54calls the on teleport end and you can
43:56replace this with a delay of 0.01
43:59seconds any small delay is enough for
44:01the um uh execution of this node to
44:04happen so we just need to give it a tiny
44:06bit amount of time usually one tick is
44:08enough so this is the safe
44:10Choice um all right so this will prevent
44:14teleporting multiple
44:16times um let's test it out so now if I
44:20play
44:22here yeah now it's only teleported once
44:25um uh but still a few problems is that
44:28the enemy can still uh damage itself and
44:32also yeah like that damage itself and
44:34also the enemy can uh move while casting
44:38what What's Happening Here Yeah so the
44:39enemy can still cast the spell while
44:42teleporting yeah like that so you don't
44:44want that sliding to happen so two
44:47things uh to prevent that sliding from
44:49happening let me just align these uh we
44:52need to tell the um the enemy to stop
44:56any Montage that's currently active so
44:58interrupt any currently active Montage
45:01uh when you start teleporting so I'm
45:04going to do it somewhere here before we
45:05actually start the AI move
45:08to um you just call uh stop anim
45:12Montage uh this if you want to stop a
45:15specific Montage you can select it uh
45:17but if you hover on the uh description
45:19here it says if null pointer it stops
45:22what's currently active so that means if
45:24you don't pass any anim mon Montage here
45:26it will just check what an a montage is
45:28currently active and stop it so this is
45:30a good way to interrupt uh the currently
45:32active Montage uh because of course a
45:35Teleport should probably interrupt the
45:37uh
45:39attack all right now the last thing is
45:41the enemy can damage herself and this I
45:45think is caused by something in the bpc
45:48attacks so I'm going to right click here
45:50and
45:51edit so in the magic spell we have this
45:55ignore actor when moving that's supposed
45:57to um prevent the enemy from damaging uh
46:01well prevent anyone calling this magic
46:04spell from being damaged um by their own
46:08spell um and we also so if I search here
46:12if I go to the projectile base we also
46:15have ignore actor when
46:18moving um on the instigator or the owner
46:22so we need to be in both places but I
46:25think I see what the problem
46:28is uh where's my bpc attacks this is not
46:32correct actually the target here should
46:34be the capsule component and the actor
46:37should be this
46:39actor uh because I'm telling this actor
46:42this projectile to ignore my uh capsule
46:47because the capsule is what has the
46:49Collision so what I need is to get the
46:54owner and get get component by
46:58class um capsule what was it called
47:01capsule component
47:03yeah and then that will be the target so
47:06I'm telling the capsule component to
47:08ignore the projectile that way it
47:11doesn't collide with
47:12it um this has been wrong for a while
47:16then so it's good that we're fixing this
47:17bug
47:19now um I think that will fix most of our
47:23problems Let's test it out
47:26again and out of sight teleport if in
47:29the middle of an attack yeah interrupts
47:32the attack
47:35perfect and isn't damaging herself
47:39anymore nice yeah she went right through
47:42it
47:43perfect uh let's test it one last
47:48time yeah I think we're
Next Up In Part 14
47:52good all right I'm going to end this
47:54video here because it's already taken um
47:57uh a while and we still have about half
48:00of the enemies the Mage enemies
48:01functionality to go uh and I'm going to
48:04continue that in the next video uh which
48:06I'll upload uh very shortly since I have
48:08everything already recorded and prepared
48:11um and in that next video we will start
48:14uh creating the custom Behavior tree for
48:16the Mage enemy and we'll also add um a
48:19new teleport eqs because right now we're
48:22using the same um ranged eqs for
48:26teleporting and we are going to add a
48:28healing functionality uh where the Mage
48:31enemy can spawn um heal area that they
48:34can stand in and heal so uh that will be
48:37coming up very shortly so if you're
48:39interested and you want to see how this
48:41continues uh please subscribe and leave
48:43a like really helps out the channel so
48:46thank you for watching and I'll see you
48:47in the next
48:48[Music]
48:54one
48:58[Music]
49:02e