Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:03,520 --> 00:00:08,110
Now, in this video, we want to add some enemies and get them moving towards the player.
2
00:00:09,340 --> 00:00:13,210
And so if we first of all, start with the zombie, let's say.
3
00:00:13,210 --> 00:00:17,200
So if we come down to a folder and.
4
00:00:18,640 --> 00:00:19,600
Let's find it.
5
00:00:26,020 --> 00:00:26,940
Oh, OK.
6
00:00:27,030 --> 00:00:30,580
Can't find the zombie for some reason and.
7
00:00:41,010 --> 00:00:41,760
Oh, there he is.
8
00:00:41,790 --> 00:00:43,950
OK, just in a folder called Prefabs.
9
00:00:44,130 --> 00:00:44,490
All right.
10
00:00:45,120 --> 00:00:48,450
I was expecting it to be in a folder called Zombies and.
11
00:00:48,450 --> 00:00:48,830
Right.
12
00:00:48,840 --> 00:00:51,300
So here is a zombie character.
13
00:00:51,810 --> 00:00:52,260
All right.
14
00:00:52,850 --> 00:00:55,130
And where is he getting this from?
15
00:00:55,210 --> 00:01:01,180
So if I just click on controller, animator, controller, it looks like it's just laid out.
16
00:01:01,200 --> 00:01:02,920
So presumably our meshes.
17
00:01:02,940 --> 00:01:03,570
There we go.
18
00:01:03,670 --> 00:01:04,890
Yes, there's the zombie.
19
00:01:05,550 --> 00:01:05,940
All right.
20
00:01:07,860 --> 00:01:09,200
And what about the animations?
21
00:01:09,200 --> 00:01:10,860
That should be a folder called animations.
22
00:01:10,890 --> 00:01:11,380
There we go.
23
00:01:11,400 --> 00:01:12,780
These are the zombie animations.
24
00:01:12,810 --> 00:01:13,200
OK.
25
00:01:14,220 --> 00:01:22,380
So down into prefabs, then we're just going to basically drag a zombie into our scene and then over
26
00:01:22,380 --> 00:01:23,370
in the scene view.
27
00:01:24,940 --> 00:01:28,680
And I'll just change back to shaded temporarily.
28
00:01:29,970 --> 00:01:32,700
I'm just going to position this zombie somewhere.
29
00:01:35,990 --> 00:01:39,680
Rotate him so that he's actually looking at the player.
30
00:01:41,360 --> 00:01:41,840
There we go.
31
00:01:42,290 --> 00:01:43,310
He just stood over there.
32
00:01:43,550 --> 00:01:45,230
Now, at the moment, he looks a little bit dull.
33
00:01:45,500 --> 00:01:47,930
That's because of the materials that are being used.
34
00:01:48,350 --> 00:01:54,530
So if I just click on this character's Z character, zero zero one can see the material and it's just
35
00:01:54,530 --> 00:01:55,610
using a standard.
36
00:01:56,060 --> 00:01:58,010
Now, it's only just one texture.
37
00:01:58,020 --> 00:02:01,190
There's no normal my pocket map or any of the other stuff.
38
00:02:02,270 --> 00:02:04,370
So we can easily just switch over to mobile.
39
00:02:04,640 --> 00:02:05,660
And on that.
40
00:02:05,750 --> 00:02:06,050
All right.
41
00:02:06,050 --> 00:02:08,630
And then suddenly these fits in with the background.
42
00:02:09,920 --> 00:02:17,370
And so what this character will need is some kind of an animator.
43
00:02:17,390 --> 00:02:17,900
There we go.
44
00:02:17,900 --> 00:02:20,780
And we've even actually got a character controller on this one.
45
00:02:21,170 --> 00:02:27,410
That means as long as I'm selecting this zombie character, I can move over to the animator and we can
46
00:02:27,410 --> 00:02:29,450
see we've got a whole bunch of animations.
47
00:02:30,200 --> 00:02:34,130
Well, we probably don't need this many animations to be on this.
48
00:02:34,130 --> 00:02:37,190
So I'm going to create my own animator controller.
49
00:02:38,000 --> 00:02:42,050
So right click, create animator controller.
50
00:02:42,630 --> 00:02:44,270
Just call it zombie.
51
00:02:46,670 --> 00:02:53,390
On the zombie character, Alex, just click and drag this into the controller and we go now start finding
52
00:02:53,390 --> 00:02:54,440
some animations.
53
00:02:54,800 --> 00:02:59,720
Well, I'm going to do I'm going to temporarily lock this on the meta window so it doesn't go away.
54
00:02:59,930 --> 00:03:01,460
So he always stays like that.
55
00:03:01,940 --> 00:03:05,900
And then that allows me then to select other things without losing access to this.
56
00:03:06,560 --> 00:03:08,330
So then I can go into animations.
57
00:03:08,750 --> 00:03:15,680
And the first thing I want is a walk animation for click on, walk over to animation, can see what
58
00:03:15,680 --> 00:03:16,490
this looks like.
59
00:03:17,020 --> 00:03:17,900
It's going to look like this.
60
00:03:18,410 --> 00:03:25,730
Just make sure that this as loop time enabled can also see that it's got some kind of root motion by
61
00:03:25,730 --> 00:03:26,210
the look of it.
62
00:03:26,900 --> 00:03:31,280
And let's drag and then walk into there.
63
00:03:31,370 --> 00:03:33,830
OK, so that that's going to be the default animation.
64
00:03:34,670 --> 00:03:36,200
And and in fact.
65
00:03:37,460 --> 00:03:40,250
We probably don't even need an attack on the nation.
66
00:03:40,730 --> 00:03:42,430
We just need this war, really.
67
00:03:43,080 --> 00:03:49,670
And so if I just take a look at this through the simulator, let's just see what this looks like.
68
00:03:53,780 --> 00:03:59,240
Oh, he is still in place, but now we can see him kind of just stood in place, sort of walking.
69
00:04:00,330 --> 00:04:03,050
At the moment, I think that walk is a little bit too fast.
70
00:04:03,230 --> 00:04:08,090
So I want to slow that down a little bit for coming to my alma mater, the animal walk.
71
00:04:08,330 --> 00:04:09,260
We have a speed.
72
00:04:09,950 --> 00:04:12,890
OK, if I want to slow this down, I'll go below one.
73
00:04:12,920 --> 00:04:18,530
So if I say zero point seven, it will slow it down a little bit.
74
00:04:25,260 --> 00:04:26,250
Venus, a bit better.
75
00:04:27,320 --> 00:04:30,530
And it looks like a slow sort of shuffling zombie.
76
00:04:31,460 --> 00:04:35,120
You can, by the way, switch between these top.
77
00:04:35,150 --> 00:04:40,690
So for example, I press play and this one and then switch over to scene.
78
00:04:40,700 --> 00:04:44,570
You can also see the character inside of the scene view actually on the meeting.
79
00:04:45,590 --> 00:04:46,880
All right, which I think is fine.
80
00:04:47,960 --> 00:04:54,710
And now what they want to do is actually get that zombi to start walking toward my main player.
81
00:04:55,010 --> 00:04:59,630
So first of all, I want something that it can target.
82
00:05:02,870 --> 00:05:05,420
I don't want it to walk directly into the player.
83
00:05:05,810 --> 00:05:07,060
The White House can look weird.
84
00:05:07,070 --> 00:05:09,560
I want it basically to walk in front of the play.
85
00:05:10,190 --> 00:05:14,990
So where we have our main camera is right click, let's choose 3D object in the cube.
86
00:05:15,320 --> 00:05:15,560
All right.
87
00:05:15,560 --> 00:05:16,700
And that's going to place this cube.
88
00:05:17,900 --> 00:05:19,340
Strike this forward.
89
00:05:21,850 --> 00:05:23,230
And I just want to scale.
90
00:05:24,900 --> 00:05:26,130
So it's not so big.
91
00:05:31,110 --> 00:05:38,370
Maybe something like that should be fine and just drag this so that it sits in front of the player.
92
00:05:38,850 --> 00:05:43,980
All right, so it looks like this could actually drag that further down toward the ground.
93
00:05:46,180 --> 00:05:46,500
And.
94
00:05:49,850 --> 00:05:51,230
Yeah, OK, that's fine.
95
00:05:52,070 --> 00:05:54,950
So we'll call this a target,
96
00:05:58,370 --> 00:06:02,830
and I want that attached to the main camera.
97
00:06:02,840 --> 00:06:05,810
So wherever the camera moves, this target will move as well.
98
00:06:06,800 --> 00:06:11,690
Now, I certainly don't want to see that target, but I do want it to have a box collider that is a
99
00:06:11,690 --> 00:06:13,580
trigger by.
100
00:06:14,300 --> 00:06:18,080
I'll just switch this off so that you can see what I've created.
101
00:06:18,620 --> 00:06:23,600
And by having the trigger, it means that whenever an object actually walks into this box, collider
102
00:06:23,600 --> 00:06:25,960
area is going to set something off in script.
103
00:06:26,250 --> 00:06:29,300
We're going to know that we're getting attacked by a character.
104
00:06:30,050 --> 00:06:31,880
Now, as I say, we don't need a machine renderer.
105
00:06:32,390 --> 00:06:39,050
And instead of just switching off the mesh renderer in Mobile, because we still technically got a material
106
00:06:39,050 --> 00:06:39,620
attached.
107
00:06:40,220 --> 00:06:43,760
It's better to right click and remove that component altogether.
108
00:06:44,250 --> 00:06:47,630
And that way, it will save any unnecessary draw calls.
109
00:06:48,710 --> 00:06:57,180
OK, so all we need to do now is get Zombi character to walk toward this target.
110
00:06:57,650 --> 00:07:00,500
I think I put my scripts folder in mobile game resources.
111
00:07:00,980 --> 00:07:05,150
OK, so I'm going to right click choose create new C sharp script.
112
00:07:05,510 --> 00:07:11,930
Now, call it enemy mode one using mobile devices.
113
00:07:12,260 --> 00:07:14,420
It's best not to use too many scripts.
114
00:07:15,020 --> 00:07:20,600
If you can get away with using maybe three or four scripts, that's a lot better than using 30 or 40
115
00:07:20,600 --> 00:07:26,990
scripts, simply because the processor has to keep open in each script and run in things like the update
116
00:07:26,990 --> 00:07:28,490
method at the start method.
117
00:07:28,820 --> 00:07:31,130
And it just takes a lot longer to do that.
118
00:07:31,570 --> 00:07:36,110
It's only got one script that it has to run the same method on that's going to make it so much faster.
119
00:07:37,910 --> 00:07:42,020
OK, but this one's necessary because I need to attach this script to the enemy.
120
00:07:42,320 --> 00:07:45,440
I can't use the main because that's attached to the main camera.
121
00:07:46,550 --> 00:07:46,970
OK.
122
00:07:47,480 --> 00:07:53,960
So what we want to do inside of this is we want to get this character to move towards the player.
123
00:07:54,620 --> 00:08:00,380
So we actually want to manipulate the transform using a vector three.
124
00:08:00,650 --> 00:08:03,830
OK, vector three is effectively an X, Y, Z.
125
00:08:04,040 --> 00:08:04,340
All right.
126
00:08:04,340 --> 00:08:05,330
Each of these vectors.
127
00:08:06,350 --> 00:08:09,320
So let's find out what we can do with a vector three.
128
00:08:09,800 --> 00:08:18,680
So if you go to help and scripting reference, this is going to open all of the necessary scripting
129
00:08:19,070 --> 00:08:21,020
that's attached to unity.
130
00:08:21,020 --> 00:08:23,330
We can type vector three.
131
00:08:25,100 --> 00:08:27,680
And then if you click the first one.
132
00:08:28,250 --> 00:08:31,880
All right, this is then going to show you everything that you can do with a vector three.
133
00:08:32,200 --> 00:08:35,810
So it's going to give you a big list of everything, which is great.
134
00:08:36,120 --> 00:08:41,120
And if you're not entirely sure what you want to achieve it, because you can just read exactly what
135
00:08:41,120 --> 00:08:41,930
these things are doing.
136
00:08:42,530 --> 00:08:45,530
What we're going to look for is something called move towards.
137
00:08:47,740 --> 00:08:49,180
OK, there it is, move towards.
138
00:08:49,450 --> 00:08:55,270
So it calculates a position between the points specified by the current and target moving no further
139
00:08:55,270 --> 00:08:58,630
than the distance specified by max distance Delta.
140
00:08:59,440 --> 00:09:03,970
OK, so in other words, it will move between its current position and the player's position.
141
00:09:04,600 --> 00:09:09,470
So if I just click on this, it's going to show you exactly how to actually write this.
142
00:09:09,520 --> 00:09:11,500
It's going to give you an example is right.
143
00:09:12,460 --> 00:09:12,900
OK.
144
00:09:14,950 --> 00:09:17,860
So it simply needs to transform, need to speed.
145
00:09:19,150 --> 00:09:22,430
And in the update, we're simply going to use this.
146
00:09:22,450 --> 00:09:25,540
OK, we're going to create a new new variable called step.
147
00:09:25,540 --> 00:09:28,840
They simply are going to be speed multiplied by time Delta time.
148
00:09:29,200 --> 00:09:32,650
So in other words, it's constantly updating and then it's transformed up.
149
00:09:32,650 --> 00:09:38,410
Position equals effect to three to move towards, transform, position, transform, target position.
150
00:09:38,830 --> 00:09:43,330
And then the step, which is the move towards OK.
151
00:09:43,990 --> 00:09:44,770
So let's do that.
152
00:09:45,640 --> 00:09:50,040
So first of all, I need access to that player target.
153
00:09:50,050 --> 00:09:56,320
So public offsite transform, we'll call player targets.
154
00:09:57,520 --> 00:10:00,910
And I'm going to need some kind of a speed, OK?
155
00:10:00,910 --> 00:10:06,460
So I'll make this public so you can change in the inspector of type float.
156
00:10:07,140 --> 00:10:08,620
We'll call speed.
157
00:10:11,150 --> 00:10:12,840
So I'm just going to save this.
158
00:10:18,420 --> 00:10:20,880
And when you attach it to the zombie character.
159
00:10:24,190 --> 00:10:31,750
And we got I got my two slots and let's take the target and set the speed at something like one.
160
00:10:34,380 --> 00:10:40,940
OK, and it's going to be in the updates, what we want to do is effectively create this step.
161
00:10:41,420 --> 00:10:45,210
So that create a new variable.
162
00:10:45,720 --> 00:10:46,170
OK.
163
00:10:46,230 --> 00:10:49,170
So you can simply just type float, create a new variable.
164
00:10:49,170 --> 00:10:58,050
So you you describe the type of variable to create Nicollet step, which is going to equal speed multiplied
165
00:10:58,050 --> 00:10:59,910
by time Delta time.
166
00:11:02,230 --> 00:11:04,470
OK, so in words, it's constantly moving forward.
167
00:11:04,680 --> 00:11:05,760
Each and every frame.
168
00:11:06,150 --> 00:11:09,260
And then we're going to take the zombies current position.
169
00:11:09,270 --> 00:11:16,770
So transform top position equals a vector 3.0 move towards.
170
00:11:18,540 --> 00:11:23,640
And then inside of the brackets, it's going to require the current position to target position and
171
00:11:23,640 --> 00:11:26,280
then the max this distance delta, which you start.
172
00:11:27,180 --> 00:11:33,390
OK, so I'm going to say transform the position as the zombies position.
173
00:11:34,020 --> 00:11:40,020
Then I'm going to say player targets, top position is where it's going to head towards.
174
00:11:40,590 --> 00:11:42,780
And then we finish that off with step.
175
00:11:43,860 --> 00:11:44,250
All right.
176
00:11:44,340 --> 00:11:44,760
That's it.
177
00:11:45,120 --> 00:11:49,260
That's how easy it is to get one object, to move towards another object.
178
00:11:50,190 --> 00:11:51,180
It's going to save that.
179
00:11:55,720 --> 00:11:57,760
And just wait for that to compile.
180
00:11:58,900 --> 00:12:00,250
And now we're going to test this out.
181
00:12:03,990 --> 00:12:08,970
OK, so we could see the zombie now walking toward me now at the moment is walking straight through
182
00:12:09,150 --> 00:12:12,240
one of those tombstones and he's also walking in mid-air.
183
00:12:12,600 --> 00:12:13,070
All right.
184
00:12:13,080 --> 00:12:13,770
Which is not good.
185
00:12:14,610 --> 00:12:20,580
Notice that he does stop right in front of the player, which is exactly what I want to go over to the
186
00:12:20,580 --> 00:12:21,570
scene view.
187
00:12:21,840 --> 00:12:23,700
We can see the zombies.
188
00:12:23,700 --> 00:12:25,860
They're still doing his walking animation.
189
00:12:26,310 --> 00:12:29,640
And so that definitely works.
190
00:12:29,850 --> 00:12:36,420
But it's not the best solution for a zombie, OK, simply because he's he's walking straight through
191
00:12:36,420 --> 00:12:38,590
these tombstones.
192
00:12:39,390 --> 00:12:41,930
It's going to be great for some of the other characters.
193
00:12:41,940 --> 00:12:43,500
So we're still going to use this script.
194
00:12:43,860 --> 00:12:46,980
We're going to do something slightly different for zombies a little bit later.
195
00:12:48,300 --> 00:12:52,080
But this script that we've created is going to be great for all the types of creatures.
196
00:12:52,290 --> 00:12:52,680
All right.
197
00:12:52,680 --> 00:12:56,340
So we're going to put a few of those in in the next video.
17491
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.