Free YouTube Transcribe

Video transcript

Smart Enemy AI | (Part 14: Mage Enemy Continued) | Tutorial in Unreal Engine 5 (UE5)

Ali Elzoheiry · 6,572 words · 30 min read

Want to search this transcript, jump the video from any line, or download it as TXT, SRT, or VTT?

Open in the transcript tool

Full transcript

Outcome of This Part

0:00[Music]

0:06welcome back everyone to Part 14 which

0:08will be the continuation of the Mage

0:10enemy and in this part we will start uh

0:14creating the custom Behavior tree for

0:16the Mage enemy and we'll also add um a

0:19new teleport eqs because right now we're

0:22using the same um ranged eqs for

0:26teleporting and we are going to add the

0:28healing functionality

0:30uh where the Mage enemy can spawn um

0:32heal area that they can stand in and

0:35heal so let's get started so right now

Explaining The Desired Mage Behavior

0:40we are still using the uh ranged enemy

0:43tree uh for this Mage uh enemy and we

0:47don't want that of course we want to

0:48create uh a separate U Behavior tree for

0:52the

0:53Mage um so to do that let me just undo

0:58the changes we made to the range so we

1:00don't mess up the ranged enemy I don't

1:02think we made any more changes yeah that

1:05was it all right so now it's time to

1:07think about the functionality we want uh

1:10or the behavior we want for our Mage

1:11enemy now what I want is that uh the

1:15Mage enemy will um keep moving around

1:19the player so um just as a ranged enemy

1:22does find a nice position around the

1:25player and keep moving there uh but the

1:28attack is going to be very different so

1:30the uh Mage enemy before attacking I

1:32want them to teleport behind the player

1:35uh because uh when you think about the

1:37behavior of your enemy you want to think

1:39how you want uh the player to react to

1:41specific uh actions to me I want the

1:44player to be able to uh to be

1:46disoriented by the Mage is they're hard

1:48to hit they don't know where they are

1:50sometimes they're here sometimes they're

1:51there and so on so the teleport should

1:54always be behind the player I don't want

1:55the Mage enemy to ever teleport

1:57somewhere next to them because then the

1:59player knows where they are at all the

2:00time so the teleport isn't really

2:03confusing so I want the um Mage teleport

2:06behind the player look at the player

2:10attack and then teleport behind them

2:12again and then um start rotating or

2:17strafing or

2:18whatever so now that I know what

Translating The Desired Behavior to the BT

2:21Behavior I want Let's uh put this all

2:23into our Behavior

2:25tree um so I'm going to actually start

2:28with a copy of the r Ed um Behavior tree

2:32and I'm going to call it BT enemy Mage I

2:35just copied the ranged Tree by the

2:38way um before I forget first thing is to

2:41actually assign it to the Mage so over

2:43here when you click on the top uh root

2:46component of your enemy uh no sorry not

2:49this one uh this one will be the Mage

2:53tree all

2:54right um

2:58so let's see what we're going to keep

3:00what we're going to change so we're

3:01going to keep the main states the Frozen

3:04seeking passive

3:06investigating um the move to line of

3:09sight also I'm going to keep the same

3:10I'm not going to keep it teleport I'm

3:11just going to keep it a normal uh walk

3:14or a run in this case um the only

3:18difference is that here we use the

3:21attack radius uh for the Mage enemy I

3:24want them to move to the defend radius

3:26because the defend radius is slightly

3:28larger uh if you all here in the uh get

3:31ideal range defend radius is 700 while

3:33attack is 500 so I want them to move to

3:37the uh further

3:39Radiance um so we keep def fend radius

3:42here this value by the way doesn't

3:43matter it's just default value if we

3:45don't Supply a Blackboard

3:47key um so this is going to keep the same

3:52uh the evade so let me just move this a

3:55bit here the evade we're actually also

3:57going to keep the same um um except when

4:01evading I want the enemy to move faster

4:03so I'm going to change their speed to

4:04sprinting because like I said I want

4:06them to be hard to hit so after they

4:08attack I want them to be moving quite

4:11fast uh and just regular movement not

4:16teleporting um all right this entire uh

4:21heal tree I'm going to delete we're

4:22going to be healing a completely

4:24different way uh I'm just going to call

4:26this

4:28heal uh um yeah we we'll get to that

4:31later now the attack this is where

4:33things are interesting so like I said I

4:36want to um teleport attack then teleport

4:40again and um then move on to the

4:45evade so um first thing we need to do is

4:50actually add the teleport eqs so right

4:52now we have a Teleport Behavior tree

4:55task if you recall and I can set the

4:57location to be the point of Interest um

5:00but the point of interest is assigned

5:02based on an eqs or environment query so

5:06I can also say run

5:08eqs and um what we were doing before is

5:11using the find ideal ranged location

5:14which is what we use here for the evade

5:17and uh oh by the way this should also be

5:19defend

5:21radius uh which is what we use for

5:23moving in line of sight or the evade but

Creating The Teleport EQS

5:27like I said the teleport I want it to

5:29always tele port behind the

5:31enemy um so we need a new eqs for that

5:35and I'm going to create this right now

5:38so let's open up our eqs folder and

5:43let's copy the seeking one because the

5:47seeking one is a cone I also want a cone

5:49so let's call this eqs

5:52teleport and to test our eqs as always

5:56where is our testing Pawn where's my

5:59testing Pawn there is my testing Pawn

6:02yeah all right so get our testing Pawn

6:07here uh make it look at the player start

6:11location and uh also don't forget the

6:15eqs context attack Target we need to

6:18move it to this testing thing so

6:20remember we make it point to the player

6:22start uh while in the editor because

6:25there is no player now in the

6:27editor and we are going to assign it the

6:30well not this one sorry search for eqs

6:32and we're going to assign it the

6:34teleport

6:36eqs all right so now we can open our

6:41teleport

6:44eqs side by

6:48side with our map so we can see what's

6:52happening all right so if the enem is

6:55here uh what I want them to do is to

6:58teleport somewhere behind behind the

6:59player so assuming this is the player

7:01this is the enemy then they should

7:03choose a point

7:05here so um I'm going to keep the cone

7:09now the cone is really important because

7:11I'm generating a cone only in front of

7:13me that meaning that means that points

7:15behind me or behind the enemy are not

7:17valid points which is what we want for a

7:19Teleport I don't want the enemy to ever

7:20teleport behind

7:22them um so I'm going to keep the cone as

7:25is but this path cost I'm going to

7:27change to be a path exist I only need to

7:30check if path exists and the trace I'm

7:33going to change to be a um see BU match

7:38here so this means requires hit actually

7:40I want the opposite I require no hit

7:42that means all the places where uh I

7:45have line of sight on the player um so

7:49this means requires no hit one also

7:52thing I want to do one interesting thing

7:54is that right now we're doing a line

7:55Trace that means if I'm standing

7:57somewhere here a line can pass so uh if

8:01just a line from the enemy to the player

8:04passes then we consider it to be a valid

8:06point but this narrow place might not be

8:09enough for my projectile spell to pass

8:12through so I want to make sure that the

8:14enemy never puts thems in a tight spot

8:17to do that I can simply replace the line

8:19Trace with a sphere Trace since the

8:21sphere is much larger it will hit a

8:23larger area and since we require no hit

8:27that means that uh if I do a sphere race

8:30of extent maybe like 40 I'm going to

8:33cancel out some of the narrow Corners

8:35somewhere like this uh that means that

8:38the enemy will never teleport to a place

8:40that's uh less than 40 units wide or

8:45they don't have in at least 40 units of

8:48visibility uh to the

8:50player um now I'm assuming that the

8:52radius of the projectile is about 40 uh

8:55I think that's about right so depends

8:56depend on your case you might want it

8:58bigger or smaller

8:59um but yeah for now this is

9:02fine um all right so uh next we want to

9:06add a distance test so I'm going to

9:09right click add a distance so I want it

9:13to be um as far away as possible from

9:19the player but within reason so uh not

9:25uh to exceed my attack radius right so

9:29let's see how we can do that let's say

9:31I'm standing somewhere

9:33here um now I want the distance to the

9:37attack Target it's very important and I

9:41want to uh filter and score or just

9:45score

9:48um if we just score or if we just filter

9:52no filter and score okay let's keep both

9:55so let's say the max value here is going

9:57to be 500

10:01um so as you can see I'm already

10:03choosing points that are um furthest

10:08away are the higher points so this three

10:10three 2.89 so these are the higher

10:12points um

10:15they're uh no more than 500 units away

10:19from the player uh but also we're not

10:21discarding anything too close to the

10:23player so I also want to discard

10:25anything that's maybe 200 units around

10:27the player um um maybe even 250 yeah

10:31something like that great um now just so

10:36you're aware right now I plug this value

10:38in 500s as um a static value but we

10:42actually want it to be the attack radius

10:45so what I can do is go to data binding

10:47and say query params and then change the

10:50name of this variable to something like

10:53um yeah just attack

10:54radius and this uh will allow us to set

10:58this value

10:59um from the eqs when we run it from the

11:02behavior tree so whatever the attack

11:05radius is um uh we're going to use that

11:09uh but for just just for testing I'm

11:11going to keep it as a static value so we

11:13see it in our

11:15editor

11:16um do we need anything

11:21else uh

11:26actually this is not

11:29we actually we do need something else

11:30cuz right now you see this point three

11:32this has the highest value even though

11:35it's not behind the enemy sorry behind

11:37the player uh but it has the highest

11:39value because it's the furthest away

11:40from the player so we need another test

11:43to make sure that it's the furthest away

11:45from the player and also the furthest

11:47away from

11:48myself uh so I'm going to add another

11:51test a distance test and this time

11:53around the

11:55querier and I'm going to um

12:01just

12:03um

12:04score and I'm going to prefer greater

12:08all right so now all these points are of

12:11lower score than these ones so now

12:14everything furthest away from me and

12:16furthest away from the player is higher

12:18score that will ensure that I'm always

12:20behind the

12:21player uh do I need anything

12:24else nope I think that's it oh and let's

12:29not forget to put this back to our query

12:33params attack

12:36radius all right and as always when we

12:39are done testing the eqs we plug back

12:43this and we move our testing Pawn away

12:47so that the enemy doesn't see it and

12:49start attacking

12:51it um great so let's now see how we can

12:56do this so if I go run eqs and say

12:59teleports it's immediately going to

13:01create this query config array for me

13:03and ask me what the value of attack

13:05radius should be and I'm just going to

13:07go to Blackboard key and say attack

13:11radius and I wanted to choose the single

13:14best item always and I wanted to store

13:16it in the point of

13:18Interest great so and then teleport to

13:21the point of

13:23interest um so if we do all of that and

13:27then wait and

13:29then um copy this paste it here so then

13:33run the eqs again then teleport

13:38again

13:41uhuh all right just cleaning this up a

13:44bit that looks like the functionality

13:47that we want um I'll make some slight

13:50changes but let me show you how this

13:52looks like first all right so enemy goes

13:55behind me as you can see but they didn't

13:57attack now they attacked and teleported

14:01behind me again then they start strafing

14:03go behind me attack teleport behind me

14:06again nice um now you'll see some

Fixing Attack Behavior

14:11strange

14:12Behavior Uh that the enemy sometimes

14:14teleports but doesn't

14:16attack um and the reason for that

14:19is uh right now the cool down is on the

14:24attack um that means that if the ranged

14:28attack is on cool down this teleport

14:30will still happen regardless because uh

14:33it's not the uh cuz it's the first thing

14:36in the sequence so the attack sequence

14:39runs because there's nothing to prevent

14:40it from running it does a Teleport and

14:43then if it is on cool down then it

14:45doesn't do anything and this whole

14:47sequence fails but I've already

14:49teleported and I don't want that I don't

14:51I don't want to teleport if the attack

14:54is on cool down and notice that this is

14:56not the only reason the range attack can

14:58fail can also fail if I don't have

15:00enough tokens let's say this attack

15:02needs two tokens instead of one now the

15:05range the Mage enemy will always be just

15:08teleporting and never attacking um and I

15:11don't want that to happen I only want

15:13the Mage enemy to teleport if they can

15:16attack

15:17so uh to do that we are going to have to

15:20move the teleport inside the ranged

15:24attack um so if you recall the ranged

15:27attack uh um also had the set Focus

15:31inside um and it had the attack start

15:34and all that so we're going to create a

15:37separate attack for the Mage uh we have

15:39one for the ranged we have one for the

15:43melee uh which sets the movement speed

15:45and does all that because this is the

15:46entire attack sequence so for the Mage

15:49the attack sequence is teleport and then

15:52attack so let's um yeah let's copy this

15:55one let's copy the ranged one paste it

15:58here and call it BTT Mage

16:03attack and let's use the Mage attack

16:06here so I'm going to delete the teleport

16:08I can keep the eqs it doesn't matter if

16:10the eqs runs continuously uh because

16:13nothing will happen it just the eqs

16:15running and um even if this is on coold

16:17down it doesn't hurt to run the eqs it's

16:20not that expensive uh if you want you

16:22can move the eqs inside the Mage attack

16:25but then it's just going to be a big

16:27mess uh to do the eqs and the teleport

16:30and the

16:32attack um all right so Mage attack and

16:36I'm going to move my cool down here and

16:40replace it this one okay and tokens

16:43needed one attack target attack

16:46Target great so let's open this up and

16:49see what we're going to do um so we also

16:53want to add the teleport here before the

16:56attack um

16:59uh and to do that we also need the

17:01teleport location so let's add a

17:04variable

17:05teleport location which is a Blackboard

17:09key selector and click the I icon very

17:13important uh now that we did that uh we

17:15can go here

17:18and uh why don't I see it yet did I not

17:21compile nope I didn't compile now that I

17:24compiled the teleport location is here

17:26that will be the point of Interest

17:29all

17:30right let me close this um okay so first

17:34if I can attack uh great I will set

17:38Focus do I want to set Focus before

17:41teleporting yeah it doesn't matter I can

17:43keep focus when teleporting but before

17:45attacking here I want to First cast to

17:50my Mage

17:51enemy uh since this is a mage attack so

17:56I'm going to cast to the mage

17:59enemy um then I don't need this cast

18:02actually since I'm casting to the

18:05Mage yeah and let me move all of

18:10this and call whoops then call

18:15teleport and the location will be the

18:19get Blackboard value as Vector for our

18:24teleport

18:27location uh

18:30and we don't want to attack until a

18:32Teleport is has ended right so that also

18:36means we want to bind so I'm going to

18:38move all of this down here a bit I

18:40should clean up these

18:41lines um assign on teleport end so

18:46attack on teleport end I'm going to call

18:49it

18:50that so once the teleport ends I am

18:54going to first uh unbind this is very

18:58important unbind from event from

19:01teleport end this event unbind it and

19:05then proceed to

19:10[Music]

19:12attack this is the attack

19:17Target o actually why why am I doing

19:21this I can just copy

19:24this this is the attack Target and I

19:26don't need the

19:44anymore so we do Attack start if we can

19:47attack we set Focus cast to a mage

19:50teleport on teleport end we unbind do

19:56the attack and on attack and we finish

20:01execution all right that looks like a

20:07proper attack sequence so back in our

20:10Mage here run the eqs do the attack

20:13sequence wait run the eqs again and

20:17teleport

20:19back

20:21perfect now let's look at it so teleport

20:26attack tele

20:28again and start strafing very nice

20:32teleport attack teleport and move

20:38away

Creating The Heal Functionality

20:40awesome all right um now I want to move

20:43on to the heal

20:46functionality um so for the heal

20:49functionality I want to use the um AOE

20:53heal that uh I showed in the AOE

20:57tutorial that uh I made a few months ago

20:59and it looks uh something like this um

21:02the uh enemy can spawn an area around

21:05themselves uh where they can um heal if

21:08they're standing inside it and I can

21:10interrupt them with an attack and

21:11prevent them from healing

21:13further now I've already migrated uh the

21:16AOE heel from that um tutorial um if you

21:20want to download the full project files

21:22for that tutorial as well um everything

21:25is uh free to download in my patreon and

21:27Link down the description um uh and for

21:30now I'm just going to really quickly go

21:32over what it is so this AOE heel um

21:36spawns this heal aura that is from the

21:39FX variety pack uh I'll also leave a

21:41link to the FX variety pack down in the

21:43description and it just looks uh

21:45something like

21:47this um so this is going to be our heel

21:50AOE and if the uh enemy standing in it

21:53they will be

21:55healing um and other than that

21:58um this AOE heel is a child of

22:03AOE base over time and this takes a

22:07spawn interval a duration and a that's

22:11it actually spawn interval is how many

22:13times uh how often the tick should

22:15happen the heel tick and duration is how

22:18long it should

22:20last um now for the heel animation

22:25itself uh we're going to create a nice

22:28Montage out

22:31of no not animation sorry and our

22:34characters Mage

22:37animations where is the

22:39heel heel yeah so

22:43this um animation I'm going to create a

22:46montage out of it to be the heal but I

22:48want it to be more like the enemy is

22:50standing in this pose for a while and

22:52then healing um so it should start like

22:55this but then keep uh in this pose for

22:57for a few seconds and let me show you

23:00how I can do that with this same

23:02animation so right click here go to

23:06create anim montage and we're going to

23:09call this the Montage

23:12Mage heel and let's move it in our

23:15montages

23:17folder

23:19wh and open it

23:22up so right now I want to start my

23:26animation at

23:28this point when I boom do my arms like

23:31this so let's say this is

23:35at

23:381.6 yeah so I'm going to click on the

23:40animation and say start time

23:441.6 and then I want it to end

23:49at here for example this is

23:560.4 yeah let's say say 0.4 so 1.6 + 0.4

24:00end time is

24:022 now this is of course a very short uh

24:06animation but this is only the first

24:07part now I'm going to go over here in

24:10the asset browser and find the heel

24:12animation again and plop it on the

24:14timeline so now I'm doing the heel again

24:18uh but this one I'm starting it at time

24:21two where the first one ends so the

24:23first one ended at two this one starts

24:24at two so it will look like a oh did I

24:27start at two no I said it ends at two

24:29sorry this one starts at two so if I

24:32play it looks like a continuous

24:33animation but the difference here is I'm

24:36going to make this one last very long

24:38while in this pose so I'm just going to

24:40make it end

24:45around here yeah this is what two which

24:50is 0.4 plus 0.6 so yeah around 2.6 let's

24:55say ends around maybe 2.5

24:59even okay actually less

25:022.4 and I'm going to make this one very

25:04slow so the play rate will be

25:080.25 see so now it stays in there for a

25:12while I actually want it to end even

25:15closer 2.3 and to be even slower

25:210.15 nice okay so the whole montage is

25:24now about 2.4 seconds and the enemy

25:28stays healing for that duration if I

25:31slow it down even more

25:330.1 then the Montage will

25:36be um 3.5 seconds great that's my

25:41Montage so um let's go back to our BP

25:45enemy in our event graph let's create a

25:48new event custom event and call it heal

25:53we can't call it heal we already have a

25:54heal and that's just the uh one from the

25:57damage system

25:58and so this one is going to be called

25:59heal over time and we're going to be

26:01using the heal from the damage system um

26:04I'm going to show you how so first thing

26:06we want to do is um play the

26:10Montage

26:12right and skeletal mesh who skeletal

26:16mesh

26:20heal all right and what we want to do is

26:24um there is no notifies just as soon as

26:26the Montage starts we want to um spawn

26:30actor from class and that's going to be

26:33the AOE

26:35heel and the spawn interval will

26:38say every 1 second yeah so the animation

26:42lasts 3 seconds let's say every 1 second

26:44we heal um 5% so then we heal a total of

26:5015% uh the duration doesn't matter now

26:53because I'm actually when the Montage

26:55ends I'm going to just destroy the this

26:57actor so let's get a reference to it

27:01um let's call it the heel

27:08AOE and we're going to create another

27:10custom event here call it

27:13heel overtime

27:17ended and the first thing we're going to

27:19do is get this heel AOE right click

27:22convert to validated get first check

27:25that it is valid and if it is then

27:27destroy

27:29actor and we will be calling this um

27:33heal ended on

27:35interrupt

27:37so because we want this to be

27:40interrupted and we're also going to call

27:41it

27:42oncomplete so if the enemy takes damage

27:45while healing um then it destroys this

27:48heal

27:49AOE all right um it's this AOE has a uh

27:55function called uh trigger now we can

27:57can call the trigger function to start

27:59it uh or we can just say trigger on uh

28:03begin play so I'm just going to click

28:04this trigger on begin playay both do the

28:06same

28:08thing um the spawn transform uh this is

28:11also going to be an interesting one so

28:13I'm going to right click on it and split

28:15the pin structure for now I'm just going

28:17to say get actor location this is going

28:20to need some modification and I'm going

28:22to show you why but for now let's just

28:24say get actor

28:26location

28:28and um then we want to pull off of this

28:31and say

28:32assign

28:35on AOE overlap actor so from the AOE

28:39tutorial uh this is the event that's

28:41dispatched when the heel ticks or when

28:45the AOE overlaps with the um actor and

28:49this happens every 1 second so that

28:51means that this is when the heel should

28:53be happening so

28:55on um heel heal tick let's call it

28:58something like that what we want to do

29:01is call the heel function and this

29:04function is from you can use the BPI

29:06damageable or the BP enemy base both are

29:09the same since we are in a child of the

29:12enemy base and what it takes is the

29:15amount to heal uh now this is an

29:17absolute amount I want to pass a

29:19percentage so to get a percentage I'm

29:21going to get my bpc damage system get my

29:25Max Health very

29:28variable and I'm going to multiply that

29:31by

29:330.05 that means

29:385% all right so now I'm healing 5% and

29:42I'm only healing

29:44myself um but actually this is this is

29:46not right because then if this AOE

29:49overlaps with any actor I heal myself I

29:53don't want to do that I only want to

29:54heal myself if I'm overlapping with

29:56myself that means I want to check here

29:59if this actor is

30:02equal to who

30:06self so only if I'm overlapping with

30:12myself then heal myself now I can also

30:16just plug in the Target here and say um

30:20heal uh but this means that anyone

30:23standing in the area will be healed uh

30:25even if the player or another

30:27depends on what you want maybe you want

30:29this AOE heal to heal anyone inside for

30:31me I only want it to heal the person

30:33that spawned it so this why this check

30:35will check if the actor that's inside is

30:38the one that spawned it and only then

30:41heal

30:43uh what

30:47else I think that's about oh and again

30:51here so this is an interesting one if I

30:52don't do an unbind here that means that

30:55every time we spawn the AOE we're

30:57creating a new bind and we're going to

30:59be healing multiple times uh so it's

31:03also important here to um

31:07unbind from AOE overlap

31:11actor let me move love these a bit

31:22here all

31:26righty

31:28[Music]

31:29um let's see do we need anything else

31:31for the heel or the heel ended so the

31:34heel end will destroy

31:37this

31:42and yeah let's test it

31:45out uh of course we need a task uh

31:48Behavior tree task for this so I'm going

31:50to go here new task uh off of BTT

31:53blueprint base put it in the tasks

31:56folder call it BTT Mage

32:01heal override the event receive execute

32:05Ai and have finish execute by now you

32:10must be pros at doing

32:12this um and I'm going to cast to my Mage

32:18because only the Mage has this heal

32:20overtime function and I'm going to call

32:23heal over time oh we need to know when

32:26the heel ended to be able to finish

32:28execution so as always we need a event

32:33dispatcher

32:35on um heal over time

32:40end and we are going to call it

32:47here then back in our task um we

32:52will

32:55assign on heal overtime

32:58end and just finish on heal end you can

33:04call it

33:07that success true don't forget

33:12that and if cast failed just for safety

33:15in case you call this on a non-mage

33:16enemy then finish with success

33:21false

33:25um what else do we

33:30need I don't think we need anything now

33:32you can have the heel um percentage

33:35being passed through here um right now I

33:38have it static so it's always uh 5% but

33:42you can have this as a parameter to the

33:45event and pass it from your behavior

33:47tree as you wish for me I'm just going

33:49to have it static as

33:515% and then here I'm going to call the

33:54heel uh Mage heel

33:58um and I'm going to add a cool down so

34:01add decorator cool down so that the

34:03enemy doesn't keep healing over and over

34:05again until they're back to 100% so if

34:08they heal once they can't heal again for

34:105

34:11seconds all right and let's do the

34:13threshold um I let's keep it

34:1730% now to test this out I want actually

34:20the enemy to start with health less than

34:2230% uh just for testing

34:25purposes so in my construction script

34:28here I'm going to pull off of my damage

34:30system and set Health to be I don't know

34:3420 or

34:35something so then they should enter this

34:38Branch

34:40immediately um oh and this also

34:43important so uh the abort right now I

34:46have it as abort both that means that as

34:48soon as your health goes below 30% drop

34:52everything you're doing and heal I

34:54actually don't want that I don't want it

34:56to drop everything is doing and heal I

34:57want to continue what it's doing and

34:59once it's done heal because you could be

35:01in the middle of an attack and then your

35:02health drops below 30% you stop the

35:05attack and heal might not be the best

35:07idea it's good to keep attacking and

35:09then heal once you're done um and the

35:12same once you have reached um the health

35:16that you want so above 30% stop healing

35:19and continue doing no I don't want that

35:21I want it to keep healing until the

35:23Montage is finished so abort will be

35:26none that means that don't abort

35:28anything lower priority because these

35:30are the only options lower priority or

35:32both and self of course so don't abort

35:34lower priority and don't abort

35:36self um oh and also maybe let's clear

35:39the focus because we don't want to be

35:42moving and staring at the player while

35:43we're we're

35:46healing uh all right let's test this out

35:48are you

35:49ready all

35:51right you are not

35:54healing you should be healing not

35:56attacking

35:58me

35:59um well you are

36:02healing but not at the time we

36:07expect let's see why so Health should

36:11start below 30% we're already starting

36:13with health below

36:1530% uh why aren't you healing

36:21then you're doing the attack and then

36:25healing but notice that the heel is also

36:28spawning in the center of the Enemy at

36:30the

36:32root um this is uh what I meant when I

36:34said that we'll have to adjust this

36:36location uh but let's see first why it's

36:39not healing as soon as it starts oh of

36:42course because we have a cool down um

36:44and the cool down starts uh counting so

36:48let me show you if I have the behavior

36:51tree running

36:52here and I play then this is UN cool

36:56cool down you see 4 seconds 4

37:00seconds now it's yeah it's counting and

37:04now the cool Down's over and then it

37:06enters let me show you

37:09again cool down is counting it's

37:11counting and now it's over now she can

37:15heal all right so kind of working as

37:18expected um there is unfortunately there

37:21is no way to tell the coold down to

37:23start not on coold down it's

37:25automatically starts uh by being on cool

37:27down uh but that's fine because the

37:29enemy won't start anyway with with

37:31health less than um uh

37:3430% uh but now let's fix the U spawning

37:38in the center so right now the location

37:42uh is the root bone or the sorry the

37:45root of the um uh the mesh which is like

37:48somewhere here in the center uh we want

37:51it to always spawn on the ground below

37:53the enemy um so we need to get the

37:55ground location

37:57to do that uh we need to do a line Trace

37:59so I'm going to move all of

38:01this and we are going going to do a line

38:04Trace by

38:08Channel and this line Trace will start

38:11from the actor location let's unplug

38:14this move this away a

38:18bit so we'll start from the actor

38:20location and then we want to uh do a

38:24line Trace vertically uh downwards until

38:27we hit something which is ideally the

38:29floor so we're going to get this

38:32multiply it by let's say negative 1,000

38:35on the z-axis that means do a line trace

38:37of length 1,000 below uh the actor

38:41location and that will be our

38:44end um and of course actors to ignore

38:49make array ignore self so that we don't

38:52hit our self oh actually we don't need

38:54to do this because we have ignore self

38:57here um all right so there's a

39:01possibility of having um a hit or maybe

39:04not having a hit so if we do have a hit

39:07that means there's a ground underneath

39:10us or something underneath us uh then

39:13what we will do is

39:15break the hit

39:17result get the location of the impact so

39:20either location or impact Point uh both

39:22are going to be roughly the same and

39:24that will be our spawn location

39:28uh but if we

39:31don't uh hit something

39:34then what do we

39:38do well then let's call um teleport

39:42[Music]

39:44end and maybe

39:49also stop anim Montage so stop playing

39:54the Montage oh we don't need teleport

39:55end we just need to stop Montage because

39:57then stop Montage will call the

39:59interrupt and interrupt will call the

40:00heal end I meant heal end actually sorry

40:02not teleport

40:04end um but that's is a rare case where

40:07we don't hit something below us that

40:09means that the enemy is trying to heal

40:11while they're in the air very high up

40:13for some reason um but it's always good

40:16to handle these edge cases as

40:19well all

40:21right

40:23uh now let's see what it looks like so

40:26the enem is going to move cool Downs 5

40:28Seconds 5 seconds later starts to heal

40:33boom excellent now everything is

40:36happening other than the enemy actually

40:38healing uh so let's see what's up with

40:42that uh so we check if the actor is

40:46equal to self then heal is this not

40:51being called I'm going to add a break

40:52point here I'm going to actually

40:54decrease this cool down where is it is

40:56it to be 2 seconds to make testing a bit

41:00easier One Mississippi two Mississippi

41:03huh so this is being

41:05called with the bpc damage system Max

41:09Health it's being called with a value of

41:13five maybe 5% is just low enough okay so

41:16let me play

41:18again 1 second

41:21later huh it was only called

41:25once

41:27oh

41:29okay yeah I shouldn't unbind now I

41:31should unbind once this is actually

41:37finished

41:38okay yeah so that is the problem I'm

41:41unbinding two early let me put this

41:46back uh let me remove this break

41:49point okay so let's see it now so now

41:54heal 5% 5% 5% 5% okay so that's a lot

42:01better uh we can make it a bit higher

42:03maybe even 7% or 8% 75 whatever U so

42:09this you'll notice it

42:11better heal heal heal heal so um now

42:16it's working correctly

42:19um I can unbind here so what I can do is

42:25uh

42:26before destroying this

42:29actor I can

42:35say uh

42:37unbind AOE all events from AOE overlap

42:43actor actually I don't think it matters

42:45if we destroy this

42:47actor yeah it doesn't matter because if

42:49we heal again we're going to spawn a new

42:51actor and bind to that new actor so we

42:53actually don't have to unbind in this

42:55case because we're destroying the actor

42:57when we're done with

42:58it yeah yeah yeah that that checks

43:02out um yeah so that's uh pretty much it

43:06now the enemy that we have let's start

43:08them with full

43:10health uh again in our construction

43:13script let's delete

43:15this so enemy starting with full

43:19health

43:21teleports attacks us teleports

43:24again attack

43:26teleport nice and then if I get their

43:29health

43:31below

43:3330% they will heal awesome and if I'm

43:38standing here I don't

43:40heal great and that is our uh Mage

Fixing Bugs

43:46enemy all right sorry before we end

43:48there's a couple of bugs real quick

43:49that's we should fix before we leave uh

43:52the first one is on the heal overtime

43:54ended uh we call the uh event dispatcher

43:57at the very end so if the heal AOE is

44:00not valid for any reason it will never

44:02be called um so it's good to always call

44:06this first before doing anything else so

44:10I'm going to call this first very simple

44:12but will save us a lot of headache in

44:14the future and the other bug I noticed

44:16is that if the enemy is currently

44:18attacking

44:19me um and I move out of live sight they

44:23continue to attack while trying to chase

44:25me

44:26um so this is uh like this sliding

44:30behavior

44:32um the reason this is happening is

44:35because uh we copied from the uh enemy

44:38range tree this canc Target with its

44:41Observer aborts so since the ranged

44:44enemy didn't have an attack sequence it

44:46can be aborted any time uh but now I

44:49don't want to abort um uh something that

44:54I'm doing uh if I can so if I'm in the

44:56middle of an attack and I suddenly lose

44:58sight of the um player I don't want to

45:01abort so I'm going to change this again

45:03to

45:04none that way if I'm in the middle of an

45:07attack come on attack me and I move out

45:11of line of sight then uh the enemy

45:15continues with their attack

45:17normally so this seems like more uh

45:21normal behavior and also remove any

45:23sliding

45:24jankiness all right and that was it as

Outro

45:28always thank you all for watching I hope

45:30you enjoyed this part and found it

45:32useful uh if you want to uh download the

45:35full project files with the mesh the

45:37animations uh all of the source code and

45:39everything uh then uh link for my

45:41patreon down in the description as well

45:43as right here um and if you found this

45:46useful uh please consider giving a

45:48thumbs up and subscribing to my channel

45:50I'll be continuing this uh series

45:52further and um eventually it will be

45:54ending on a uh um boss fight AI uh might

45:58not be the end but I got a lot of

46:00requests to make a boss fight so I'm

46:02going to be working my way towards that

46:04so if this is something that uh sounds

46:06interesting for you please consider

46:08subscribing and um as always I'll see

46:11you in the next

46:12[Music]

46:24one oh

This transcript was generated from the captions YouTube publishes for this video. Get the transcript of any YouTube video atfreeyoutubetranscribe.com: free, unlimited, no sign-up.