All language subtitles for 001 Making the First Enemy AI[UdemyIran.Com]

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian Download
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,050 --> 00:00:04,130 In this video, we're going to do something very exciting and create our first enemy AI. 2 00:00:04,160 --> 00:00:06,230 We already have an enemy blueprint, right? 3 00:00:06,230 --> 00:00:11,090 With the crab that we can attack, that can be defeated, that can deal damage to us, but it doesn't 4 00:00:11,090 --> 00:00:12,020 really have a brain. 5 00:00:12,020 --> 00:00:13,790 It's not really doing anything. 6 00:00:13,790 --> 00:00:17,150 So through AI behavior, we can make it walk left and right. 7 00:00:17,150 --> 00:00:21,710 For example, turn around if it hits the wall and turn around before it walks down a ledge. 8 00:00:21,710 --> 00:00:25,760 And this is going to be a simple implementation for the crab that you've probably seen in many retro 9 00:00:25,760 --> 00:00:26,660 games before. 10 00:00:26,690 --> 00:00:32,360 There is a big problem in misconception with AI in Unreal Engine though, and nobody really knows how 11 00:00:32,360 --> 00:00:33,440 to do it properly. 12 00:00:33,440 --> 00:00:39,020 There's barely any good tutorials and everybody just thinks they are supposed to use behavior trees, 13 00:00:39,020 --> 00:00:42,410 because this is the one AI feature that comes with Unreal Engine. 14 00:00:42,410 --> 00:00:48,080 But behavior trees are very complicated, and actually you don't need something that complex for most 15 00:00:48,080 --> 00:00:49,220 AI applications. 16 00:00:49,220 --> 00:00:55,520 So the way that I use AI mostly and teach AI is to simply implement the AI in the AI controller through 17 00:00:55,520 --> 00:00:56,180 blueprints. 18 00:00:56,180 --> 00:01:01,610 So let's start by creating a base AI controller that is shared between all of the enemies, and then 19 00:01:01,610 --> 00:01:03,770 make an AI controller for the crab. 20 00:01:04,160 --> 00:01:09,590 So here in the content drawer, we go to blueprints and we can just right click here and make a new 21 00:01:09,590 --> 00:01:11,270 folder called AI. 22 00:01:11,860 --> 00:01:15,490 And in here we can right click again blueprint class. 23 00:01:15,490 --> 00:01:18,340 And the one we want is not in the comment section. 24 00:01:18,340 --> 00:01:21,100 We actually have to look for AI controller. 25 00:01:21,310 --> 00:01:27,220 And here you see the AI controller above below the controller. 26 00:01:27,220 --> 00:01:29,770 So we just want to use this one and click on select. 27 00:01:29,770 --> 00:01:34,900 And I'm going to call it AIC base because again this is just for all of the enemies. 28 00:01:34,900 --> 00:01:37,330 If we maybe want to have something to share in there. 29 00:01:37,330 --> 00:01:43,870 And after that we just want to right click and create Child Blueprint class and called AIC crab for 30 00:01:43,870 --> 00:01:44,650 the crab. 31 00:01:44,650 --> 00:01:46,300 And now let's open this up. 32 00:01:47,030 --> 00:01:50,330 In here again, you see the viewport, you see an event graph. 33 00:01:50,330 --> 00:01:52,670 And this is also just a regular blueprint. 34 00:01:52,670 --> 00:01:56,330 However, on the right side you can see that we already have a lot of things implemented here. 35 00:01:56,330 --> 00:02:00,620 Here we have a lot of settings for the AI and things like that, but we don't really have to worry about 36 00:02:00,620 --> 00:02:00,860 those. 37 00:02:00,860 --> 00:02:05,330 We can just leave them at the default setting for now, and you could tweak them later on if you need 38 00:02:05,330 --> 00:02:05,480 to. 39 00:02:05,480 --> 00:02:10,310 But basically everything that we need for the AI to work is already here with the component and the 40 00:02:10,310 --> 00:02:14,510 path following component, and all of the things that we have here, and we can just build on top of 41 00:02:14,510 --> 00:02:15,110 that. 42 00:02:15,260 --> 00:02:17,870 Again, just so you know, what we want to build for the crab. 43 00:02:17,870 --> 00:02:19,940 The crab isn't an aggressive enemy. 44 00:02:19,940 --> 00:02:21,470 It doesn't really care about the player. 45 00:02:21,470 --> 00:02:22,910 It doesn't have to detect the player. 46 00:02:22,910 --> 00:02:27,230 It just kind of minds its own business and it's always just going to walk forward. 47 00:02:27,230 --> 00:02:29,870 So here if we start, it's going to start walking forward. 48 00:02:29,870 --> 00:02:34,820 And then if it hits the wall, we want it to detect that it hits the wall and then turn around and then 49 00:02:34,820 --> 00:02:35,780 just walk forward. 50 00:02:35,780 --> 00:02:40,310 And then if it detects, oh, I'm going to fall down a ledge, we're going to catch it and turn it around 51 00:02:40,310 --> 00:02:40,550 again. 52 00:02:40,550 --> 00:02:43,520 So it's just going to go back and forth back and forth. 53 00:02:43,520 --> 00:02:47,690 And I'm pretty sure you've seen enemies like this thousands of times in many platformer games. 54 00:02:47,690 --> 00:02:49,880 And that is the first one I want to teach you. 55 00:02:50,650 --> 00:02:54,280 And you could also implement all of that simply in the crabs blueprint. 56 00:02:54,280 --> 00:03:00,130 That would also work, but it's a better separation of concerns pattern to use an AI controller here. 57 00:03:00,130 --> 00:03:05,290 And we can treat the AI controller kind of like the brain of the crab in this case, and it's going 58 00:03:05,290 --> 00:03:09,400 to give instructions to the crab of what it should execute and what it should do. 59 00:03:09,430 --> 00:03:12,880 Here we also have the on Beginplay event and the on tick event. 60 00:03:12,880 --> 00:03:18,940 But actually with an AI controller you have to be careful because the Beginplay event is actually a 61 00:03:18,940 --> 00:03:20,170 little bit dangerous here. 62 00:03:20,170 --> 00:03:24,070 There is a better event we can use which is called on possess. 63 00:03:24,670 --> 00:03:25,990 Event on possess. 64 00:03:26,770 --> 00:03:33,100 And this is triggered not when the AI controller spawned, not when the game is started, but if this 65 00:03:33,100 --> 00:03:35,530 AI controller possesses a pawn. 66 00:03:35,530 --> 00:03:38,920 And this is also going to tell us which pawn we are possessing. 67 00:03:39,220 --> 00:03:44,890 The problem that happens on Beginplay is that sometimes the AI controller will spawn before the actual 68 00:03:44,890 --> 00:03:52,030 pawn spawns, and if we then try to get a pawn, for example, get controlled pawn, right? 69 00:03:52,030 --> 00:03:56,980 So if we try to get the controlled pawn on beginplay, sometimes it is not going to have a reference, 70 00:03:56,980 --> 00:04:01,000 it's just going to be null because they were spawned not in the correct order. 71 00:04:01,000 --> 00:04:02,800 So we got to be careful with Beginplay. 72 00:04:02,800 --> 00:04:05,230 Let's actually just delete it so we don't make any mistakes. 73 00:04:05,230 --> 00:04:11,050 It is better to just use the event on possess, and we also get the pawn right here and can save it, 74 00:04:11,050 --> 00:04:12,520 can use it however we want. 75 00:04:12,520 --> 00:04:13,840 And how do we want to use this? 76 00:04:13,870 --> 00:04:18,610 Well first we want to cast to be enemy grab. 77 00:04:19,730 --> 00:04:22,190 Like this and save this. 78 00:04:22,190 --> 00:04:25,520 So promote the variable and just say owning grab. 79 00:04:27,540 --> 00:04:28,350 Like this. 80 00:04:29,950 --> 00:04:34,330 And now we can use this in other parts on tik and other parts of this AI. 81 00:04:34,360 --> 00:04:34,720 Controller. 82 00:04:34,720 --> 00:04:35,470 Blueprint. 83 00:04:36,280 --> 00:04:43,270 And just to show how this works, we want to print string, print string and just print the owning crab. 84 00:04:43,330 --> 00:04:48,280 And right now if we start, well, nothing is going to print because we still have to tell the crab 85 00:04:48,310 --> 00:04:50,560 to use this AI controller. 86 00:04:50,830 --> 00:04:57,700 So I can go to the content drawer, go to blueprints, characters enemies, and have the enemy crab 87 00:04:57,910 --> 00:04:59,830 and open up the full blueprint. 88 00:04:59,830 --> 00:05:02,800 And here, while this is selected, just look for AI. 89 00:05:03,890 --> 00:05:05,510 And scroll down. 90 00:05:05,810 --> 00:05:09,890 And here you can see the AI controller class. 91 00:05:09,950 --> 00:05:15,620 And instead of the general AI controller we just select this and use the AIC grab. 92 00:05:16,100 --> 00:05:22,670 And if we just start the game now you can see here we can see it prints the BP enemy crap at the top 93 00:05:22,670 --> 00:05:23,240 left. 94 00:05:23,980 --> 00:05:26,440 So this proves to us that this is actually working. 95 00:05:26,440 --> 00:05:28,960 This is getting the reference of the crap and it's saving it. 96 00:05:28,960 --> 00:05:30,610 So we can then use it here. 97 00:05:30,610 --> 00:05:37,180 One important setting here though, is also on the enemy crap under eye you can see auto possess eye, 98 00:05:37,180 --> 00:05:40,120 and this is a setting that trips up so many of my students. 99 00:05:40,120 --> 00:05:45,880 I've seen it hundreds of times and honestly, I don't understand why this is the default setting placed 100 00:05:45,880 --> 00:05:46,510 in world. 101 00:05:46,510 --> 00:05:53,110 This means that the eye controller is only gonna possess this pawn if it is placed in the world. 102 00:05:53,110 --> 00:05:58,090 However, if you spawn it through a spawn system or something like that, it is actually not going to 103 00:05:58,090 --> 00:06:02,440 be possessed by the eye controller and it's just going to be floating in the air. 104 00:06:02,440 --> 00:06:06,790 And we want to set this to spawn a placed in world or spawned. 105 00:06:06,790 --> 00:06:09,700 So it's gonna control the pawn in both cases. 106 00:06:09,700 --> 00:06:11,980 But actually we don't want to set this in a crap. 107 00:06:11,980 --> 00:06:17,830 We want to set this in the enemy base, because this is a setting we want to have for all of them. 108 00:06:17,830 --> 00:06:19,510 So VP enemy base. 109 00:06:19,630 --> 00:06:21,940 And here just look for eye again. 110 00:06:21,970 --> 00:06:28,900 And all the way at the bottom we just want to set this to placed in world or spawned compile and save. 111 00:06:28,900 --> 00:06:31,030 And now you can see in the enemy crap. 112 00:06:31,030 --> 00:06:33,610 It is also changed because we changed it in the parent. 113 00:06:33,610 --> 00:06:37,960 And now this is going to be applied to all of the enemies we're going to create later on. 114 00:06:38,890 --> 00:06:41,920 And now we are ready to give the crab instructions. 115 00:06:41,920 --> 00:06:43,510 And what do we want the crab to do? 116 00:06:43,540 --> 00:06:46,870 Well, just tell it to walk forward constantly. 117 00:06:46,870 --> 00:06:51,580 But first we have to create a function in the crab to walk forward because we haven't actually implemented 118 00:06:51,580 --> 00:06:53,230 anything in the crab. 119 00:06:53,230 --> 00:06:55,540 So here we can just make a custom event. 120 00:06:56,500 --> 00:07:00,190 Custom event and call it Walk Forward. 121 00:07:01,420 --> 00:07:02,440 Like this. 122 00:07:02,440 --> 00:07:07,270 And here, just like for the player, we want to trigger the add movement. 123 00:07:07,300 --> 00:07:08,380 Input. 124 00:07:09,300 --> 00:07:10,560 Add movement input. 125 00:07:11,990 --> 00:07:19,220 And the world direction in this case, because we always want to walk forward, is not just typing X 126 00:07:19,220 --> 00:07:23,330 on the one, but here we actually just want to get actor forward vector. 127 00:07:23,330 --> 00:07:26,990 So we always walk in the direction our actors pointing towards. 128 00:07:26,990 --> 00:07:28,550 And for the scale value. 129 00:07:28,550 --> 00:07:31,880 Well, we had a controller here for the player right. 130 00:07:31,880 --> 00:07:35,480 So for the player it could be minus one for left and plus one for right. 131 00:07:35,480 --> 00:07:38,750 But now the AI controller is going to give us this value. 132 00:07:38,750 --> 00:07:41,180 So we can just go here and place it here. 133 00:07:41,880 --> 00:07:46,530 Like this and just expose it, make it an input and I can compile and save. 134 00:07:46,530 --> 00:07:48,690 And now in the AIC grab on tick. 135 00:07:48,690 --> 00:07:55,050 Because on every frame we want to slowly walk forward, I can just get well, first of all get rid of 136 00:07:55,050 --> 00:07:57,690 the print string here and here on tick. 137 00:07:57,690 --> 00:08:01,290 Because on every frame we want to walk forward, just get the grab. 138 00:08:01,710 --> 00:08:06,960 And here just walk forward, which is the custom event we created here. 139 00:08:06,960 --> 00:08:07,650 Right. 140 00:08:07,650 --> 00:08:08,910 Just call this. 141 00:08:12,390 --> 00:08:17,280 Go like this and always just have the scale value of one, which is a full walk. 142 00:08:18,350 --> 00:08:22,520 And this is the equivalent of just tilting your stick all the way to the right. 143 00:08:23,700 --> 00:08:24,690 And let's check this out. 144 00:08:24,720 --> 00:08:27,090 Now I can compile, save and go here. 145 00:08:27,090 --> 00:08:29,010 And the crab is walking forward. 146 00:08:29,040 --> 00:08:29,550 Right. 147 00:08:29,550 --> 00:08:30,690 It might be a little bit hard to see. 148 00:08:30,690 --> 00:08:32,370 So we can just go to simulate instead. 149 00:08:32,370 --> 00:08:33,030 Right. 150 00:08:33,030 --> 00:08:35,340 And you can see the crab is walking forward. 151 00:08:35,340 --> 00:08:37,440 But it is very very fast. 152 00:08:38,990 --> 00:08:42,650 Let's just put in another crap so we can better test how fast it is. 153 00:08:42,650 --> 00:08:44,360 Because here we're just going to hit the wall right away. 154 00:08:44,360 --> 00:08:48,980 So we can just select the crab, hold alt on the keyboard, and drag off from this red arrow to make 155 00:08:48,980 --> 00:08:49,730 a copy. 156 00:08:49,730 --> 00:08:53,120 And again, we can see that it is very fast. 157 00:08:53,120 --> 00:08:59,600 So in the BP enemy crab we can just click on the character movement component. 158 00:08:59,600 --> 00:09:02,780 And here we look for max walk speed. 159 00:09:03,360 --> 00:09:07,110 And it is 600 right now, which is exactly as fast as our player. 160 00:09:07,110 --> 00:09:13,530 But crabs are supposed to be very slow, so just put it to 120 and we can compile, save and check it 161 00:09:13,530 --> 00:09:14,280 out now. 162 00:09:14,280 --> 00:09:19,350 And yeah, I think this is a good value for our simplest and easiest enemy. 163 00:09:20,060 --> 00:09:24,860 And yeah, this is working fine, but you can see that we are only playing the idle animation. 164 00:09:24,860 --> 00:09:29,090 And just like we did for the player, we want to check that if we are moving, we want to play the walking 165 00:09:29,090 --> 00:09:30,290 animation instead. 166 00:09:31,040 --> 00:09:32,360 And to set up the animation. 167 00:09:32,360 --> 00:09:36,230 We actually have two choices now and we can go through the content drawer. 168 00:09:36,260 --> 00:09:42,440 Go to content, paper, assets, characters, enemies, and crab. 169 00:09:42,440 --> 00:09:48,530 And you can see that we have way fewer animations here than we have for our player, right? 170 00:09:48,530 --> 00:09:52,850 And for something as complicated as the player, of course, we want to use paper because it gives us 171 00:09:52,850 --> 00:09:53,870 much more control. 172 00:09:53,870 --> 00:09:55,490 It makes calling events easier. 173 00:09:55,490 --> 00:09:58,910 It gives us this nice animation graph where we can also use jumps. 174 00:09:58,910 --> 00:10:03,170 But for this simple character, we just have an idle animation and a walk animation. 175 00:10:03,170 --> 00:10:07,730 So it is actually very easy for us to just control this in the regular blueprint without relying on 176 00:10:07,730 --> 00:10:12,230 the Paper XRD plugin, just using the basic paper 2D functionality. 177 00:10:12,230 --> 00:10:15,230 And here there is no really wrong or right way, right? 178 00:10:15,230 --> 00:10:21,260 Because if we go to blueprints, characters and player right, you can see we had to create this animation 179 00:10:21,260 --> 00:10:25,340 source, we had to create this animation blueprint, and then we had to set it up in here. 180 00:10:25,340 --> 00:10:31,850 So we had to go through a bunch of different steps to set up the Paper XRD for this character. 181 00:10:31,850 --> 00:10:36,500 And since the setup takes some time, it makes it more worth it the more we're going to implement. 182 00:10:36,500 --> 00:10:40,580 But for the crab, I believe just implementing this in the blueprint is actually quicker and simpler 183 00:10:40,580 --> 00:10:41,990 than using Paper XRD. 184 00:10:41,990 --> 00:10:44,930 And I actually want to show you that this is also an option. 185 00:10:44,930 --> 00:10:48,830 But in the end, you kind of can decide for yourself if you just want to have everything use the same 186 00:10:48,830 --> 00:10:50,450 method, that is fine too. 187 00:10:50,450 --> 00:10:53,420 I just want to show you that both of these options are available. 188 00:10:53,870 --> 00:10:59,330 So now in the BP enemy crab, we want to go to the tick function here. 189 00:11:01,070 --> 00:11:05,660 And we just want to create a new function and call it update Anim. 190 00:11:05,900 --> 00:11:07,520 It's called update anim. 191 00:11:07,730 --> 00:11:10,940 And we want to now call this on tick right. 192 00:11:10,940 --> 00:11:13,640 So after the parent tick just call the update anim. 193 00:11:13,640 --> 00:11:17,180 And in here we're just going to implement our animation switching now. 194 00:11:17,180 --> 00:11:19,010 And how do we do this without paper. 195 00:11:19,460 --> 00:11:21,530 Well we're not going to use the animation component. 196 00:11:21,530 --> 00:11:23,150 We're not going to use an animation blueprint. 197 00:11:23,150 --> 00:11:24,980 We can just get the sprite. 198 00:11:24,980 --> 00:11:27,620 And actually this is a flipbook component. 199 00:11:27,620 --> 00:11:29,690 So the name sprite is a little bit unfortunate. 200 00:11:29,690 --> 00:11:31,790 But we can't change it because it's inherited. 201 00:11:31,790 --> 00:11:34,190 But this is actually a flipbook right. 202 00:11:34,190 --> 00:11:37,850 This flipbook that is playing here and we can directly affect it. 203 00:11:39,060 --> 00:11:40,470 So back here right. 204 00:11:40,470 --> 00:11:42,690 We want to set flipbook. 205 00:11:43,310 --> 00:11:47,660 Which is a built in function here, and just drag it off like this. 206 00:11:47,660 --> 00:11:50,600 And here we can then select which flipbook we want to place. 207 00:11:50,600 --> 00:11:54,650 So just type in grab and we can then select do we want to play the idle or do we want to play the walk. 208 00:11:54,650 --> 00:12:01,910 And we decide this based on our velocity so we can get velocity. 209 00:12:02,580 --> 00:12:03,540 Like this. 210 00:12:03,900 --> 00:12:06,000 And here just the vector length. 211 00:12:06,000 --> 00:12:08,190 Because we don't care about the direction. 212 00:12:09,220 --> 00:12:14,590 And we just want to check if this is bigger than zero, which means we are moving. 213 00:12:14,590 --> 00:12:16,960 And we can then use this with a select here. 214 00:12:16,960 --> 00:12:18,430 So I can just select. 215 00:12:19,030 --> 00:12:21,670 You could also use a branch and then put this in here. 216 00:12:21,670 --> 00:12:22,270 Right. 217 00:12:22,270 --> 00:12:25,900 So then I just get a true and false flipbook. 218 00:12:26,290 --> 00:12:29,230 So if this is true then we know that we are walking. 219 00:12:29,230 --> 00:12:29,980 We are in motion. 220 00:12:29,980 --> 00:12:33,310 So here I can just select the crab walk. 221 00:12:33,310 --> 00:12:34,900 And for false we are idle. 222 00:12:34,900 --> 00:12:37,120 So I can just select the crab idle. 223 00:12:37,120 --> 00:12:38,770 And you could also use a branch here. 224 00:12:38,770 --> 00:12:39,070 Right. 225 00:12:39,070 --> 00:12:43,390 But I think the select is just makes it easier to look at and makes it simpler. 226 00:12:43,390 --> 00:12:45,250 And this is all it takes right. 227 00:12:45,250 --> 00:12:49,330 So this was way quicker than setting up the animation source, setting up the animation blueprint, 228 00:12:49,330 --> 00:12:52,540 and doing all of those things so I can just compile and save. 229 00:12:52,540 --> 00:12:58,750 Now go here simulate and you can see we are playing the walk animation now properly. 230 00:12:58,750 --> 00:13:03,580 And now the next thing we want to do is to make the crab spin around once it hits the wall. 231 00:13:04,030 --> 00:13:05,830 And for this there are also multiple methods. 232 00:13:05,830 --> 00:13:10,090 We could use a line trace again like we did for the player to detect the wall. 233 00:13:10,090 --> 00:13:15,070 But I want to show you the other alternative options, and there's not really one option that is better 234 00:13:15,070 --> 00:13:15,760 than the other. 235 00:13:15,760 --> 00:13:17,950 It kind of depends on your preference and the case. 236 00:13:17,950 --> 00:13:20,620 But here I'm going to use a box collision. 237 00:13:21,100 --> 00:13:24,100 So in the enemy crab go to the viewport. 238 00:13:24,100 --> 00:13:31,600 And while the capsule component is selected just click on add and look for box Collision like this. 239 00:13:31,600 --> 00:13:34,630 And we then want to put this to the front side. 240 00:13:34,630 --> 00:13:34,870 Right. 241 00:13:34,870 --> 00:13:36,490 You can see this arrow here. 242 00:13:36,490 --> 00:13:42,400 If I click away this uh bluish light blue arrow this is the forward direction. 243 00:13:42,400 --> 00:13:46,750 And we want to have the box in front of the player the crab. 244 00:13:46,750 --> 00:13:50,710 But first we also want to rename it to Wall Detector. 245 00:13:52,370 --> 00:13:55,100 So here we want to move it over to the right side. 246 00:13:55,100 --> 00:13:58,640 And here make it a little bit shorter. 247 00:13:58,640 --> 00:14:00,020 Smaller on this side. 248 00:14:01,170 --> 00:14:03,360 The with back and forth is fine. 249 00:14:03,360 --> 00:14:05,880 It should be around the same as the capsule. 250 00:14:06,820 --> 00:14:09,730 And then we want to move it over here where the claw ends. 251 00:14:10,290 --> 00:14:14,190 So we're gonna start turning around once we hit this area. 252 00:14:15,900 --> 00:14:20,700 As always, we now have to set up the collision for the wall detector, so select it on the right side. 253 00:14:21,210 --> 00:14:23,880 And again, we don't have to make a preset for this. 254 00:14:23,910 --> 00:14:24,720 This is very simple. 255 00:14:24,720 --> 00:14:31,230 So just go to custom, ignore everything and overlap only world static because again floors. 256 00:14:31,230 --> 00:14:33,120 Walls are usually world static. 257 00:14:34,240 --> 00:14:38,680 And now go to the UN compound begin overlap event, add it. 258 00:14:38,680 --> 00:14:40,240 And for now other actor. 259 00:14:40,240 --> 00:14:41,920 We just want to print string here. 260 00:14:42,690 --> 00:14:48,090 Print string the other actor like this and let's check it out. 261 00:14:48,420 --> 00:14:51,000 There's actually going to be one problem, but let's have a look. 262 00:14:51,030 --> 00:14:53,160 It doesn't detect the wall. 263 00:14:53,160 --> 00:14:57,810 And this is actually a problem with the settings on the cube grid tool output. 264 00:14:59,280 --> 00:15:01,770 If we go in here and look for collision. 265 00:15:02,940 --> 00:15:06,180 You can see that we are using the default settings for the collision presets. 266 00:15:06,180 --> 00:15:10,590 So this part is fine, but we actually cannot generate overlap events. 267 00:15:10,590 --> 00:15:15,870 So if you open this up a little bit more you can see that generate overlap events is not checked. 268 00:15:15,870 --> 00:15:20,340 So make sure on the cube grid tool output to check generate overlap events. 269 00:15:20,340 --> 00:15:21,450 And you got to be careful. 270 00:15:21,450 --> 00:15:23,340 There's actually two that are similar. 271 00:15:24,960 --> 00:15:28,260 Right there is generate overlap events during level. 272 00:15:29,290 --> 00:15:30,730 Uh, level streaming. 273 00:15:30,730 --> 00:15:32,650 We only care about the first one. 274 00:15:32,650 --> 00:15:35,980 If you make a level with level streaming, then yeah, you might also want to check this. 275 00:15:35,980 --> 00:15:38,260 So we can just check both just to make sure. 276 00:15:38,870 --> 00:15:42,320 And then get out of here and let's try it again. 277 00:15:43,140 --> 00:15:47,340 And now you can see we are actually printing this reference to the cube grid tool. 278 00:15:47,340 --> 00:15:48,810 So this is working fine. 279 00:15:48,810 --> 00:15:51,660 Now we just have to actually turn the crap around. 280 00:15:51,660 --> 00:15:56,940 If this happens to do that, we just need to create a function that turns the crab around. 281 00:15:56,940 --> 00:16:01,170 But this seems like a very general thing that we might also use in other enemies. 282 00:16:01,170 --> 00:16:04,500 So I think it's better to just put this in the BP enemy base. 283 00:16:04,500 --> 00:16:12,120 So make sure to open up the BP enemy base and create a new function and just call turn character. 284 00:16:14,200 --> 00:16:17,890 And here we just want to set actor rotation. 285 00:16:18,910 --> 00:16:19,990 Like this. 286 00:16:20,350 --> 00:16:21,580 And what do we want to do? 287 00:16:21,580 --> 00:16:23,680 Well, we want to get the current rotation. 288 00:16:23,680 --> 00:16:25,870 So get actor rotation. 289 00:16:26,820 --> 00:16:32,580 Because we need to know if we are looking left or right right now, and we can actually just add 180 290 00:16:32,580 --> 00:16:35,970 degrees to it so we can combine rotators. 291 00:16:37,270 --> 00:16:39,100 Here and on the Z. 292 00:16:39,100 --> 00:16:39,610 Right? 293 00:16:39,610 --> 00:16:43,870 Because if you look here the Z axis sorry. 294 00:16:43,870 --> 00:16:45,970 Got to go here on rotation. 295 00:16:45,970 --> 00:16:46,240 Right. 296 00:16:46,240 --> 00:16:49,840 The z axis is the one that turns us around in this way. 297 00:16:51,410 --> 00:16:53,690 Right, but set it back to zero. 298 00:16:53,990 --> 00:16:55,850 And this was just to show you. 299 00:16:55,850 --> 00:16:56,420 And yeah. 300 00:16:56,420 --> 00:17:02,750 So back in the function we just want to put 180 for the Z and then connect this here. 301 00:17:03,610 --> 00:17:07,450 And this is all it takes to turn the character around here in the function. 302 00:17:07,450 --> 00:17:10,630 And now we just want to call this in the BP enemy crab. 303 00:17:10,630 --> 00:17:19,270 So instead of the print string here we can just call turn turn character like this. 304 00:17:19,750 --> 00:17:21,099 Now let's check it out. 305 00:17:21,099 --> 00:17:22,540 Can go back to the map. 306 00:17:22,540 --> 00:17:23,440 We hit the wall. 307 00:17:23,440 --> 00:17:24,280 We turn the character. 308 00:17:24,280 --> 00:17:27,490 It's working fine, but now we're actually falling down the ledge. 309 00:17:27,490 --> 00:17:29,740 And again, this depends on what kind of game you're making. 310 00:17:29,740 --> 00:17:34,600 Maybe you want to have this kind of behavior, but in this case, I also want to show you how we can 311 00:17:34,600 --> 00:17:36,820 detect the ledge and then turn around at the ledge. 312 00:17:36,820 --> 00:17:39,100 There's actually one more cool thing we can easily add. 313 00:17:39,100 --> 00:17:43,360 And if we just copy the crab again, hold alt and pull here. 314 00:17:44,120 --> 00:17:47,360 And you can see that now they just walk through each other. 315 00:17:47,910 --> 00:17:49,770 But we can actually easily set it up. 316 00:17:49,770 --> 00:17:53,100 So they also start turning around if they hit each other. 317 00:17:53,100 --> 00:17:57,570 So on the enemy grab for the wall detector. 318 00:17:57,570 --> 00:18:03,060 If we set world dynamic to overlap as well, this is actually going to work. 319 00:18:03,060 --> 00:18:05,100 And now if we do this. 320 00:18:05,960 --> 00:18:08,780 They kind of hit each other and turn around as well. 321 00:18:09,590 --> 00:18:13,580 And this is, I think, a really cool effect that you also see in a bunch of these games. 322 00:18:15,230 --> 00:18:19,880 With this though, we have to be a little bit careful and for now world dynamic is fine. 323 00:18:19,880 --> 00:18:23,930 But as you add more things, there's maybe going to be other things in world dynamic that you don't 324 00:18:23,930 --> 00:18:24,830 want to affect this. 325 00:18:24,830 --> 00:18:30,470 So later on maybe we want to add another preset, but for now this is fine as long as we don't have 326 00:18:30,470 --> 00:18:30,920 any bugs. 327 00:18:30,920 --> 00:18:33,950 And I think it's just a little nice cool effect that we can add. 328 00:18:33,950 --> 00:18:35,870 So let's now get into the ledge detection. 329 00:18:35,870 --> 00:18:37,790 And this works in a similar manner. 330 00:18:37,790 --> 00:18:45,410 Again, while the capsule component is selected click on Add and look for box Collision again like this. 331 00:18:45,410 --> 00:18:49,040 And this one we want to call Ledge Detector. 332 00:18:49,810 --> 00:18:50,590 And this one. 333 00:18:50,590 --> 00:18:56,830 We also want to drag it over to the side and make it a somewhat similar size to the other one. 334 00:18:57,660 --> 00:18:58,620 Like this. 335 00:18:59,860 --> 00:19:01,450 But this one is actually important. 336 00:19:01,450 --> 00:19:06,820 We want to move it downward because this is always going to check if there is a floor overlapping with 337 00:19:06,820 --> 00:19:07,840 us or not. 338 00:19:07,840 --> 00:19:08,410 Right. 339 00:19:08,410 --> 00:19:09,400 So it's always going to check. 340 00:19:09,400 --> 00:19:12,880 And this actually we can go a little bit more left like this. 341 00:19:12,880 --> 00:19:17,320 And yeah we always want to make sure that a floor is in this collision. 342 00:19:17,320 --> 00:19:22,060 And the moment we don't detect any floor in here, we're actually going to start turning around. 343 00:19:22,060 --> 00:19:25,720 And here again on the right side we got to set up the collision settings. 344 00:19:25,720 --> 00:19:31,960 And here again we can just go to custom ignore everything and only check for world static. 345 00:19:32,850 --> 00:19:38,880 And here we actually want to use the opposite event not begin overlap but actually end overlap. 346 00:19:39,780 --> 00:19:41,880 Because we want to turn around the moment. 347 00:19:41,880 --> 00:19:44,280 There is no floor beneath us anymore. 348 00:19:45,050 --> 00:19:46,280 Just add this. 349 00:19:49,030 --> 00:19:56,260 And here we can also just copy paste this turn character like this and put it here and compile and save. 350 00:19:56,260 --> 00:19:57,610 And let's check this out. 351 00:19:58,390 --> 00:19:58,900 Right. 352 00:19:58,900 --> 00:20:00,970 We hit the ledge and we turn around. 353 00:20:03,390 --> 00:20:06,210 And this is how easy it is to implement this system. 354 00:20:08,160 --> 00:20:08,640 Right. 355 00:20:08,640 --> 00:20:15,000 And everything we've done here in the AI controller is literally just a walk forward on the event tick, 356 00:20:15,000 --> 00:20:17,760 and everything else happens in the BPM. 357 00:20:17,790 --> 00:20:20,730 You could have also done this on tick in the BPM, right? 358 00:20:20,730 --> 00:20:26,130 But it is a better separation of concerns pattern to kind of treat the AI controller like the brain. 359 00:20:26,130 --> 00:20:31,200 So the brain is going to tell it walk forward, walk forward, walk forward and the body is the enemy 360 00:20:31,200 --> 00:20:31,920 craft blueprint. 361 00:20:31,920 --> 00:20:34,230 It's going to execute what it's being told. 362 00:20:34,230 --> 00:20:37,890 And this pattern becomes more useful the more complicated your enemies get. 363 00:20:38,220 --> 00:20:41,250 Next up, we're going to make an enemy that can shoot projectiles. 34200

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.