Full transcript
Outcome of This Part
0:00[Music]
0:06welcome back everyone to part 16 of our
0:08smart enemy AI Series in the last part
0:11uh we added this jump attack and in this
0:14part we're going to add this really cool
0:16spinning sword attack where the enemy
0:18spins the sword chases the player around
0:21and I get hit if I'm inside its
0:24range nice so let's get
0:28started all right so the first thing I
Animation/Montage Setup
0:31want to show you again as always is the
0:33animation that I'll be using so I want
0:35to use this uh spinning sword animation
0:37I got from mixo and retargeted to the
0:40unreal mannequin of course and I'm also
0:42going to be using this uh effect uh that
0:45is from the Infinity Blade effects acid
0:47pack uh which I will also leave a link
0:49down in the description for uh both free
0:51to
0:52use um all right so the first thing we
0:54want to know about this animation is how
0:56we want to use it or what Montage will
0:58create out of it so how I want the
1:01attack to look like is I want it to have
1:03like a relatively long windup time so
1:05this part should be relatively slow and
1:09then this spin part should happen
1:11relatively fast and then once the
1:14animation reaches this point where the
1:16sword is held um sort of um at an angle
1:21to the body I want the uh mesh to start
1:24spinning around uh I'm not going to play
1:27the full animation because the animation
1:28doesn't have any spinning but I'm going
1:29to pause the animation here and spin the
1:32actual mesh um so let's see how we're
1:35going to do that so first thing let's
1:37create our Montage so go to our
1:39animation rightclick create an montage
1:44Call It
1:45Montage um sword spinning attack or
1:52something and uh let's open up our
1:54Montage so the Montage is going to have
1:57three parts as I mentioned a windup time
1:59a fast Spin and a pause at the end so
2:02that means I need to use this animation
2:04three times so I'm going to search for
2:06it here sword spinning attack put it
2:09once put it twice and put it three
2:12times so for the first time I want it to
2:14end somewhere
2:17around here like uh somewhere around
2:20here maybe 0.5 so start time 0 point oh
2:26sorry not start time end
2:28time uh uhuh so ends around
2:33here actually let's make it end a bit
2:35early maybe
2:390.42 all right yeah and then we start
2:43this animation at the time where the
2:44other one ended so this one starts at
2:470.42 and say ends sometime
2:51around yeah right
2:54here uh which is
2:580.85 so let's see how this looks like
3:01now starts here and ends here great and
3:06now we want this to start at
3:090.85 and we want it to just stop or like
3:12not stop but play for a very long time
3:14very slowly so I'm going to have it
3:16start at 0.85 and end at 0.86 which is
3:20obviously very very short uh but I'll
3:23have the play rate how fast it plays to
3:25be very very slow so something like
3:280.0 2
3:30five so this makes it a lot longer and
3:35now now let's take a look at all of it
3:37goes like this yeah and very moving like
3:41in almost in slow motion but the mesh
3:43itself will be spinning so it's not
3:44going to look like that and the wind up
3:46time I want it to be a bit slower as
3:48well so let's say the wind up time is
3:520.5 yeah so to give the player enough
3:55time to react like and spin something
3:58like that
4:00and that's um that's our Montage yeah
4:03looks pretty good now let's start adding
4:05some uh notifies to it I'm going to have
4:08two notify tracks so I'm going to add
4:10the track here now the first thing we
4:13want to do is uh we want to add a slash
4:17sometime
4:18around here so let's right click and
4:22notify Montage notify let's call this
4:25one slash so this does a um like the uh
4:29the sword slash that does the sphere
4:31trace and the
4:32Damage uh and then we want to actually
4:35start spinning at some point right so I
4:39want the notify to tell us in the
4:41blueprints when to start spinning the
4:42mesh so maybe sometime
4:46around here we want to notify Montage
4:50notify let's call it
4:53spin great now we want two more
4:56things um well right now let's say we
5:00want the effect first so we want to play
5:02the um uh this spinning sword effect
5:05that I showed you so let's say we start
5:08at somewhere like around here and we
5:11play the uh um this uh effect so right
5:15click add notify and choose play
5:17particle
5:18effect uh make sure it's like at the
5:21time we're standing at which is
5:241.41 and the particle itself is going to
5:27be uh this I forgot it's name but we
5:29don't have a lot yeah it's this one
5:32spinning spinner L
5:35to uhhuh so it's going to play
5:39here and it's playing at the bottom so
5:42let's add an offset to it so add like 75
5:46to the z-axis so it plays yeah where the
5:49sword is and also let's make it bigger
5:51so I'm going to scale it up to two on
5:54each
5:56axis yep that looks better so looks like
5:59this
6:01boom and the problem is it's a bit short
6:03so it ends before the Montage ends so
6:05I'm going to play it again before it
6:07ends so yeah it ends somewhere around
6:113.2 or something right so I'm going to
6:13copy this and paste it again here around
6:173.31 whatever no
6:213.3 yeah so now uh it should look like
6:25it's continuous so there we go and yeah
6:30yeah that's pretty close and it ends as
6:32the Montage
6:33ends uh perfect I think this looks good
6:36for now um now let's start creating the
Adding The Attack Function
6:39actual attack the spinning sword
6:42attack U so I'm going to go over to my
6:45melee enemy
6:48here and go to Let's close a bunch of
6:51these
6:52things let's go to my event graph and
6:55over here where we have uh our three
6:57attacks let's give ourselves
7:00some
7:00[Music]
7:04room move all of
7:07this all right now we're going to create
7:09a new custom event and call it the uh
7:13spinning sword attack or spinning Attack
7:17Just spinning attack is fine and as
7:19always it takes as input the attack
7:23Target which is of type
7:28actor and
7:29let's just copy everything we had here
7:32and paste it
7:35here attack target attack target attack
7:39Target and let's see what's
7:41different um so it doesn't have a jump
7:43so I'm going to delete this jump and
7:46delete this of
7:49course um and the Montage that it's
7:51going to play is our spinning
7:55sword
7:56Montage mhm yep
8:00and it's not going to be interruptable
8:03and attack ends the same great so now
Spinning Functionality
8:05what we need to do is implement this uh
8:08spin so what happens when we reach the
8:10spin notify in our anim Montage
8:13right so to do that let's go over here
8:17to our uh we call them attack
8:20helpers and add our
8:24spin custom event call it uh spin mesh
8:30cuz yeah technically we're spinning the
8:31mesh
8:33itself um and let's see how we're going
8:37to do that so I'm going to do uh I'm
8:40going to use a timeline to do the spin
8:42so right click add timeline and if you
8:45don't know what a timeline is uh well
8:47let me just first name it I'm going to
8:49call it the spin mesh timeline now a
8:53timeline allows you to do um a specific
8:56action or to do something over time so
8:59I'm going to double click it to open it
9:00up and uh first thing you need to do is
9:03you need to add a track so I'm going to
9:04add a float track because we want to
9:06change the rotation value so the Z
9:09rotation value of our mesh over time and
9:12so I'm going to add a float track since
9:13the Z rotation is a float value and I'm
9:16going to call it um Z rotation Alpha and
9:21I'm calling it Alpha here because it's
9:23uh a value from 0 to one not the actual
9:26rotation um and I'm going to show you uh
9:30why now the next thing we do is decide
9:33the length of this um uh of this
9:37timeline how long is it going to play
9:39for so for our Montage uh the Montage
9:43duration itself is about so here I can
9:46see it's 5.2 seconds but we start
9:48spinning at 1.2 seconds so from the
9:52moment we start spinning till the moment
9:54the Montage finishes it's about 4
9:56seconds so I'm going to make uh the
10:00uh uh this timeline also 4 seconds now
10:03it's not really going to matter that
10:04much because once the Montage is
10:06interrupted or finishes we're going to
10:07stop this timeline anyway so even if the
10:09duration is longer it's not going to
10:11make that big of a difference but it
10:12will affect your spinning speed of
10:14course all right so now we have our
10:17track let's right click somewhere here
10:18add a value and at Time Zero it's going
10:22to be zero and add another one and at
10:24time four which is the end the value is
10:26going to be
10:28one so it's basically a linear line from
10:310 to 1 over 4
10:34seconds and how we're going to use it is
10:36you go back here uh let's say play from
10:39start now this update is called uh every
10:42tick with the new value so let's say um
10:45the I'm currently 2 seconds through so
10:48the Z value is going to be 0.5 if I'm at
10:510 seconds then this value is going to be
10:53zero and if I'm at the end this value is
10:54going to be one so what I want to do is
10:57update the rotation of of the mesh
10:59itself not the whole actor so I need to
11:02first know what value we're starting
11:05with so I'm going to get the mesh I'm
11:07going to get its relative rotation now
11:10I'm getting relative rotation here not
11:12World rotation um because uh the mesh
11:15already starts with a relative rotation
11:17of 270 or something so I don't want to
11:20addit to the world rotation and then not
11:21know what the relative one was anyway so
11:24I'm starting with the relative rotation
11:25and I'm going to promote that to a
11:27variable and I'm going to call it
11:29uh mesh rotation before
11:34spin excellent so this is going to be
11:37stored right before do the timeline and
11:40then I'm going to get the mesh again and
11:42say set relative rotation on each update
11:46so whenever this timeline updates uh I
11:49want to set the new rotation value now
11:52once the rotation value going to be I'm
11:53going to right click and split this the
11:56X and Y won't change so I need to get
11:58this mesh rotation before spin split it
12:03get the X and Y these are going to be
12:04the same now the Z is going to change
12:07now how do you use an alpha value and to
12:10tell it to uh if it's zero use this
12:12value if it's one use that value uh it's
12:14something called aurp so linear
12:17interpolate so it takes an alpha a value
12:19between 0 and one and if the alpha is
12:21zero it uses a if the alpha is one it
12:23uses B and anything in between it uses
12:26whatever value is in between so when we
12:28first start when zero we want it to use
12:31the rotation value of the z-axis before
12:34the spin
12:35starts and at one so at the very end we
12:38want it to spin let's say 10 12 whatever
12:41a certain amount of times so we need to
12:43take this value and add to it the number
12:47of times you want to
12:48spin so one spin is
12:51360° so this is one spin 720 is two and
12:55so on now you can quick tip here you can
12:59actually write mathematical functions in
13:01here right away so if I want to spin 12
13:03times I can do 360 * 12 and it's going
13:05to calculate it for me uh another nice
13:08tip first of all this is going to be
13:10plugged into the B and this is going to
13:12be plugged into the Z Now another nice
13:14tip if you don't want to do the
13:16mathematical function here uh there's uh
13:18also something called a math expression
13:20node so I can right click here say math
13:24expression and write it here 360 * 12
13:29and then this is going to give me a
13:30value that I can just plug in here and
13:32if you by if you double click this and
13:33open it up you'll see what it's doing uh
13:37so it's it's a really cool way to do um
13:39oh where's my event graph it's a really
13:41cool way to do mathematical expressions
13:43in an easy way of course you can have
13:44very complex things here as
13:47well uh all right so then we rotate 12
13:53times over 4
13:57seconds so let's uh uh let's test this
13:59out um first let's call this spin mesh
14:04here spin
14:07mesh right and uh we want to call the
Using The Attack In The Behavior Tree
14:11spinning attack
14:13itself uh and we do that in our Behavior
14:16tree so BT enemy
14:20melee so right now we only have two
14:22attacks the short range attack and the
14:24long range attack and if you recall from
14:26the previous tutorial uh this
14:29enum is what chooses the attack to play
14:32so we actually need to add the name of
14:34the short range attack to our enum so
14:36I'm going back to my enemies folder AI
14:40sorry not AI uh melee enemy open up this
14:44enum e melee attacks and add an
14:46enumerator call it the spinning
14:50attack all right so now that we have
14:53this enum we can actually start using it
14:55here just for testing I'm going to
14:57remove both of these let's move them
15:00away and I'm only going to do the uh
15:03spinning attack so melee
15:06attack uh attack oops attack Target key
15:10is the attack Target the attack radius
15:13um let's say defend radius you don't
15:14have to be close to do it tokens needed
15:17one and attack name spinning
15:20attack and then let's open it up and we
15:23need to implement the spinning attack
15:25here so pull off of my melee enemy and
15:29just call spinning attack and plug it in
15:32here and plug in your attack Target as
15:35well oh and of course plug it in here
15:38when you're done I don't know why I have
15:39a print
15:43here all
15:45right just let's uh let's later on move
15:49all of um all of this to a function to
15:52make it a bit cleaner because right now
15:53it's a bit messy you can have functions
15:55inside your behavior tree tasks by the
15:57way
15:59all right so now I'm only doing the
16:01spinning attack and doing nothing else
16:02Let's test this out show me what you're
16:08doing very nice
16:11spinning and if I'm close I get hit once
16:15because now we only call slash once so
16:17I'm getting hit once but actually we're
16:19going to do the hit in a different way
16:22uh than just using the
16:24slash uh but this is looking pretty
16:27cool um now we actually want the enemy
Chasing The Player When Spinning
16:30to start chasing uh their attack Target
16:33while they're
16:35spinning so as soon as you start
16:36spinning we want them to chase as well
16:39so we're not going to do this in the
16:40behavior tree we're still going to do
16:42all of this in
16:45the well actually we can do it in the
16:47behavior
16:49tree so in our melee attack we can say
16:55spin well or chase and then attack but
16:59the problem
17:02is yeah yeah the problem is we don't
17:06know when to start chasing because
17:08that's defined by the Montage we want
17:09the chase to start when the spin starts
17:12so it's defined by the Montage so let's
17:14let's keep it now at the enemy uh
17:17blueprint and uh we can move it later on
17:20so as soon as you start spinning we want
17:22to chase the player here right but we
17:25don't have a Chase uh function yet so
17:27let's create that and our helpers
17:30here I'm going to create a new custom
17:34event and we're going to call it
17:37Chase um attack Target and it takes as
17:41input the attack
17:44Target so the chase is going to be very
17:47simple it is going to um we're going to
17:50do an AI move
17:53to uh we're going to do this off of self
17:56so we're moving ourselves
17:59and we're moving to our attack Target
18:01with an acceptance radius of um I don't
18:05know let's
18:06say 200 you don't have to be really
18:08close because the spin is large so 200
18:11should be
18:11fine and then on success once you reach
18:15the target you want to continue chasing
18:16right so on success let's do a short
18:19delay maybe yeah 0.1 seconds or
18:22something and then call Chase attack
18:25Target
18:27again
18:28why does this called new
18:31Pam Chase huh that is
18:35weird
18:40refresh why are you called new Pam
18:43you're called attack Target here I
18:46refresh you
18:49maybe very strange Chase attack oh now
18:52it's good okay weird bug
18:56anyway uh and we're going to call it in
18:59this attack Target uh but we also want
19:02to um stop uh chasing once the Montage
19:06finishes right uh or once the attack is
19:09over so one easy thing we can do is if
19:12you recall uh we call U parent attack
19:16when we begin the attack and we call
19:17attack end when the attack is over now
19:20what these do is in our base enemy um
19:23all they do is set attacking to True
19:26when we call attack and attack and sets
19:29attacking back to false so what we can
19:31do is check in our melee
19:34enemy uh if we're still
19:38attacking so we can get our attacking
19:41Boolean
19:42value if we are attacking then continue
19:45chasing if we're not attacking then
19:47don't call the chase again and that's an
19:50easy way to stop it from chasing once
19:52the attack is
19:54over all right so we're going to call
19:56Chase here right after the spin so Spin
19:58and Chase the attack
20:03Target
20:07great now let's test this out
20:10again should attack and Chase meoo very
20:16nice and then once the attack is
20:19over cool so obviously um a few things
20:23we need to do first let me show you what
Polishing The Spinning Functionality
20:25we what we do if we get interrupted
20:29so right now we say that the enemy can't
20:30be interrupted once they're doing this
20:33so I can remove that or just unplug this
20:36so the enemy is
20:38interruptible and this is going to be
20:39really weird so if the enemy is
20:41interruptible I can attack him now he's
20:45still he's still spinning right and we
20:48don't want that let me show you again
20:52interrupt and he's still
20:54spinning so we want to as soon as the
20:57enemy is uh interrupted to um uh to just
21:02stop the uh current spin uh function
21:06right so to uh prevent this from uh
21:10happening uh we want to have a way to
21:12stop this timeline right luckily you
21:16could just pull a plug here uh that does
21:18a stop uh or say put a pin here that
21:22calls uh stop uh or you can also uh just
21:26call it yourself so
21:28uh I can go here in the attack end H get
21:31a reference to my timeline search for it
21:33it's called the
21:35spin I'll just search for timeline yeah
21:37get spin mesh timeline this what we
21:39called it and I'm going to just say
21:44stop and that's it so once the timeline
21:48is uh so once the attack is over or is
21:51interrupted then call stop on the spin
21:53mesh timeline so let's see this again
21:55I'm going to make interruptible true so
21:58he is always
21:59interruptible try to attack me I'm going
22:01to interrupt him and boom spinning is
22:04over now he started again because there
22:07is no cool down on it but oh ah this is
22:10another problem so you see once I
22:13interrupt
22:14him uh he can be looking in the wrong
22:17direction so let me show you once it's
22:19over see he's not even looking at me
22:21because the mesh is rotated in the wrong
22:24direction so we also want that as soon
22:26as stop is
22:28to um reset the mesh to where it was so
22:34I'm going to create a new custom event
22:35for that I'm going to create a custom
22:38event and call it stop
22:42spinning uh let's add it here below the
22:48spin so what stop spinning does is just
22:51this
22:52part it calls stop on the mesh this is
22:57the same exact thing as just plugging
22:58this here by the
23:00way um and then what it should do is
23:03reset the mesh to its original location
23:05so gets the mesh set
23:08relative
23:10rotation to this value this mesh
23:12rotation before
23:14spin uh which is in our variables
23:18here um mesh where is it mesh rotation
23:21before spin yeah and just plug it in
23:24here so now it stops and resets the
23:27rotation of the mesh uh because you
23:29couldn't be stopping at a weird value of
23:31course should we do anything else on
23:34stop uh nope that's it let me add a
23:39small cool down to this so that it
23:41doesn't keep playing over and over again
23:43cool down let's
23:45say two seconds so then you can see what
23:49things actually look like and I'm going
23:51to interrupt
23:53him he's he's still spinning why is he
23:56still spinning did we not call
23:58oh we didn't we didn't call the stop
24:00spin so on interrupt here call stop
24:03spinning very important to call the
24:06functions you create all right so again
24:09I'm going to interrupt
24:12him uh what happened there again
24:17spin
24:19interrupt he is is he looking at me
24:21correctly let me do it in slow
24:26motion
24:28I don't know I don't think the mesh was
24:30reset to its original value was
24:33it no it's
24:38happening no I think it's happening but
24:40there was this one weird time where it
24:41didn't happen why was
24:45that yeah it's happening I think if I
24:49call
24:51interrupt before spin happens then the
24:56value of um ah okay so this is a weird
24:59so if I interrupt right at the very
25:03beginning now even closer like come
25:09on now yeah so now he reset the value
25:13before actually setting the value so he
25:16we called Uh set relative rotation to
25:19mesh before spin when this value is not
25:21even set because we didn't begin
25:23spinning so let's actually make sure
25:25that this value is
25:28valid or let's actually just
25:33default um this value to be whatever the
25:36mesh starts with so the mesh starts with
25:38a default value yeah so let's give it a
25:41default value and we can do this in
25:44the construction script so in the very
25:48beginning we are going to get our mesh
25:50we're going to get its relative
25:53rotation and we are going to get the
25:56mesh rotation before spin and set that
26:00value great so now this will always have
26:04a
26:05value let's try this again so interrupt
26:08at the very beginning of the spin before
26:14spinning nope I was too
26:19slow now yeah he's starting to spin
26:22interrupted yes and his rotation is
26:24still
26:25good yes again let's see yes right
26:28before spinning interrupt yes rotation
26:31is good perfect so this works as
26:34expected
26:36now now the next thing we need to do is
Adding AOE Damage To The Spin
26:38actually get damaged by this spin so
26:41right now we only get damaged by the
26:42first slash this one um and even I was
26:46too far so I didn't get damaged but we
26:47want the actual spinning sword to keep
26:51hitting us and for that I'm going to be
26:54using the um AOE damage um um actor that
27:00we have now I use I used this for the
27:02AOE heel before uh and this is part of
27:04my uh AOE tutorial and I'll leave a link
27:08for it if you want to check it out uh
27:10but this in this tutorial we created a
27:11function or a bunch of actors that can
27:13do damage or heal in an
27:17area um so this is uh what it looks like
27:21this AOE base uh it takes um it has a
27:25radius a a debug sphere and it can spawn
27:30um uh an sphere in a specific area and
27:33checks what's overlapping with this
27:35sphere and this is what we're going to
27:37do we're just going to spawn a sphere
27:39around us uh and check if the enemy or
27:43the target is in there and going to
27:44damage them uh and we want actually to
27:47do this periodically so let's say we
27:49want to do a hit every 0.5 seconds or
27:54something so this should be controlled
27:56by our
27:58Montage so right here let's say here we
28:01do a slash right so then somewhere
28:04around
28:071.5 yeah let's start with 1.5 we start
28:10doing an attack uh this AOE attack uh so
28:13anyone in range of this spin will get
28:15damaged and let's keep doing it um like
28:19every 0.5 seconds right so I'm going to
28:21right click
28:23here add notify Montage notify let's
28:26call it uh
28:28AOE um slash something like that and
28:31right click change the time to be
28:331.5 and I'm going to do it every 0.5
28:37seconds so copy and
28:38paste this one will be at two copy paste
28:44next one at
28:472.5 copy paste next one at three copy
28:52paste next one at
28:563.5
28:58copy paste whoop next one at
29:02four copy paste next one at wow I'm
29:06getting really close 4.5 and finally the
29:09last one copy paste this one at five
29:15great so every 0.5 seconds we call this
29:18AOE slash now we need to go back to our
29:21melee enemy and handle what happens so
29:24in
29:26our here in our switch statement let's
29:30add a third one and call it AOE slash
29:33make sure you don't have typos
29:35here so what do we do on AOE slash let's
29:38create another attack helper for that so
29:41go over here custom events AOE
29:46slash by the way all of these attacks
29:48and attack helpers will be moving to our
29:50bpc attacks once we start our boss
29:52fights because they're all going to be
29:53shared for this tutorial I'm just
29:55creating them all in the enemy but we'll
29:56move them to their rightful place uh
30:00eventually all right AOE slash um now
30:04few things to consider do you want it to
30:06only damage your target or do you want
30:08it to damage anyone in the area for me I
30:10only want it to damage my attack
30:14Target um so I'm going to add a attack
30:20Target um input as well so what do we do
30:23is going we're going to spawn an actor
30:25from class and it's going to be our AOE
30:29base now generally I wouldn't use the
30:32base right away I'd create a child class
30:34for it but since I pretty much only want
30:36the functionality in the base I don't
30:38want any other functionality um this
30:41should be
30:42enough and the spawn transform I'm going
30:44to split it it's going to start at our
30:47actor location wherever the actor is and
30:52um I'm going to draw debug sphere just
30:53so that we see it and I'm going to say
30:55trigger on begin Play If I don't do
30:57trigger on begin play I just have to
30:58pull off of this and call trigger
31:01myself
31:03um so we're going to say trigger on
31:05begin play oh actually I don't want to
31:07trigger on begin play because I want to
31:08set the radius first um so I'm going to
31:12pull off of this and say set radius to
31:15be um I don't know I think 300 should be
31:18good uh we'll
31:20see and then I want to call
31:26trigger
31:29uh do I want to do anything
31:33else nope but now what happens when uh
31:37after we trigger what happens when uh
31:39someone gets damaged so oh before the
31:42trigger we need to bind so pull off of
31:44this and say assign on AOE overlap actor
31:48so this is the event that's dispatched
31:50when the sphere overlaps with anyone so
31:53let's say damage actor on or AOE damage
31:59actor something like
32:01that and we bind then we
32:05trigger and we are going to check is
32:08this actor uh equal to our attack Target
32:12so if this
32:13value is equal to our attack Target that
32:17way we're ensuring that we're only
32:19damaging our attack Target if you want
32:21to damage anyone in the area then don't
32:23do
32:24this uh and if that is true then take
32:28our actor and call take
32:31damage message yeah the one with the
32:35message uh damage causer is
32:38self and oh also here instigator is
32:43self um ignore instigator is is
32:45important to not call uh this on
32:48ourselves but we're already checking if
32:50it's not so it doesn't really matter and
32:52then here let's make our damage info do
32:55I don't know like 10 damage
32:58melee and hit
33:02reaction we're not using anything other
33:05than the amount for now so everything
33:06else that I just set is useless but I
33:08just like to set it anyway for when we
33:10start using
33:12it all right so now we just need to call
33:16AOE
33:18slash here AOE
33:21slash and pass in our attack
33:25Target
33:28looking like a nice uh staircase all
33:30right let's see how this looks like in
33:33play and boom one two three four yeah
33:38you see I think the oh I'm dead oh I'm
33:42dead then I can still move that is very
33:45interesting we're going to fix that bug
33:48uh but first let's uh I want to decrease
33:50the damage a lot so that I don't die
33:52let's just make it one damage and let's
33:54see what's going on in slow motion now
33:57so we do the sphere
34:01Trace there we go and I'm inside it so
34:05oh sorry let me show you again slow
34:07motion sphere
34:09Trace come on and
34:14whoop yeah and I think the sphere Trace
34:17is large enough right I don't think we
34:18need to change its
34:20size uh yeah it's actually just on the
34:23edges might need to be a bit bigger but
34:26it's good to give the player some uh um
34:28like some safety zone and then each time
34:31this spere sphere spawns if I'm in it I
34:33get
34:35damaged and let's see normal speed now
34:39enem is going to attack me if I get
34:40caught in it I get
34:43damaged
34:45perfect um so one thing I noticed is
Modifying Player Hit Response (with animation blending)
34:49that if I'm getting damaged uh we
34:51disable input right um and we disable
34:54input and I can't pretty much move so if
34:57this spinning attack hits me just once
35:00I'm pretty much stuck in it it's very
35:02difficult to get out of it um so I'm
35:05going to make a small change to the
35:07player's hit reaction uh in our BP
35:10player if you
35:13recall uh hit
35:15reaction where is hit
35:18reaction let me just search hit
35:21reaction
35:24hit uh hit respond
35:28response what was it
35:30called on damage response
35:36yes um what we do is we disable input
35:38then we play this montage and then we
35:40enable input again um I don't want every
35:43hit to disable input this we were just
35:45doing for testing I think it's a bit
35:47extreme so I'm just going to play the
35:50Montage um but if I do that what will
35:54happen is I can still move while the
35:55Montage is playing and it's going to
35:57look a bit awkward so let's see what
35:58this looks like so I'm moving but my
36:01legs aren't moving so I'm just sliding
36:04you see that I'm getting hit so my legs
36:05aren't moving and I'm just sliding so we
36:08need to do the same thing that we did
36:10for the um player sorry for the enemy in
36:12the last tutorial and blend the two um
36:16uh animations so the lower part to use
36:19the regular walking animation and the
36:21upper part of the body to use the um hit
36:24reaction so going over over to our ABP
36:28player our animation blueprint for the
36:30player and going over to our anim graph
36:35we're just going to copy everything so
36:36go to Manny again and copy this part
36:41well first we need to actually cache
36:43this
36:44pose uh so we need to Cache our main
36:47state so unplug this and again as a
36:51reminder we search for cash new saved
36:53cach pose and this is like storing the
36:55whole state in a variable to use later
36:57on and we're going to call it main
37:00states now I can copy all of this good
37:06stuff and paste it right
37:08here
37:10whoops
37:16yep all right um this should work now if
37:19I
37:21play now I should be blending so I'm
37:24going to hit and my feet oh my feet are
37:26are still not moving because we forgot
37:29to tell the Montage to play only the
37:31upper
37:32body uh so this Montage go to it and
37:36change the slot to upper
37:40body great now if we play Let's watch
37:44again getting hit and I'm hitting and
37:47I'm moving so you see now I'm getting
37:49hit the upper part of the body is
37:51playing the hit animation while the
37:53lower part of the body is moving
37:54normally so this looks a lot more
37:57natural so I can still get hit but I can
38:00escape from this uh spinning attack so
38:03if I get caught in it I get hit I get
38:05damaged but I can still Escape otherwise
38:07you get hit once and you're pretty much
38:09dead so it's very op so now we need to
Modifying The Behavior Tree With 3 Attacks
38:12actually play this um uh to play this
38:16attack when we are
38:19um when we actually need it right so in
38:22our Behavior tree we just play it all
38:24the time uh but now you should think
38:26about when you want to start using this
38:28attack to me it feels like uh a bit of a
38:31a powerful attack compared to the other
38:33ones so I'm just going to give it a
38:34cooldown like a very high coold down of
38:37uh shouldn't delete that uh you can say
38:41um 20 seconds or something and if it is
38:43on cool down then do check if you can do
38:46a long range and if you can't then do a
38:49short
38:49range so it's a very simple behavior and
38:53this selector we can call it uh like
38:55possible attacks or something like that
38:58so it just uh this is on the left most
39:01so as soon as this becomes available the
39:03cool down is over then do it do the Spin
39:06Attack if it is on coold down check are
39:09you in range I changed this by the way
39:11from 400 to 350 I thought felt better uh
39:14if you are greater than 350 units then
39:17do the long range attack and otherwise
39:19do the short range attack and I also
39:20added the cool down of two seconds here
39:23so if this is on coold down you're not
39:24within long range and this is on cool
39:27down then go to the strafe sequence
39:30obviously play with these values to make
39:32your enemy as powerful or as weak as you
39:34want them uh but I think this will work
39:35for now so let me change this just to I
39:39don't know 7 Seconds to display what it
39:41looks like um in an attack sequence so
39:44first he's going to jump because he was
39:46far away then he's going to do the
39:47normal one then it's on cool down so
39:50he's going to do the spin boom boom boom
39:52boom boom
39:54great um and and it's going to go back
39:57to attacking again everything's on cool
39:59down so he's
40:00strafing and once I'm dead I'm
40:03dead oh we should also fix that bug
40:05where I died and I can still move uh but
40:07first of all let's um stop uh sorry
40:11let's remove this debug sphere we don't
40:13need it anymore we don't need to keep
40:15drawing it uh and I think I know what
40:18happens when I died then I could still
40:20move um so once
40:24we actually I don't think think it's
40:26going to happen anymore because once we
40:28die where is it the on
40:31death uh magic spell HUD Chang yeah so
40:34on death we disable input so we can't
40:36move but if you recall in the hit
40:39reaction just before I changed it um it
40:42had an enabled input so if I die while
40:45the hit reaction Montage uh is still
40:48playing or gets
40:49interrupted uh then we call enable input
40:53but we're not doing that anymore so this
40:55should uh so this shouldn't happen
40:56happen again so if I change the melee
40:59enemy damage to 10 which should kill me
41:03in five hits cuz my health is 50
41:05now or even less do the spinning and if
41:10I'm moving I'm moving getting attack and
41:13now I can't move
41:16great nice it's looking really good as
41:19always thank you all for watching if you
41:21enjoyed this part please consider giving
41:23a like And subscribe and um as I
41:25mentioned the last tutorial uh I'm going
41:27to be adding more and more abilities to
41:29each different enemy type so we'd have a
41:32large array of different uh attacks that
41:35we can do and then once we have that in
41:37place we're going to see how we can make
41:39these attacks uh reusable so that we can
41:42put them all in a boss fight um because
41:44U boss fights usually contain a combo of
41:48different attacks that you've already
41:49learned by um seeing them in previous
41:52weaker enemies so this is going to show
41:54you how progression build up in games
41:57and how a boss fight is just a stronger
41:59version of the mechanics that you've
42:01already encountered before so if this
42:04sounds interesting to you uh stay um
42:06subscribe to stay in touch and uh as
42:09always I'll see you in the next
42:12[Music]
42:25one