Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Now, in this video, we want to add some enemies and get them moving towards the player.
And so if we first of all, start with the zombie, let's say.
So if we come down to a folder and.
Let's find it.
Oh, OK.
Can't find the zombie for some reason and.
Oh, there he is.
OK, just in a folder called Prefabs.
All right.
I was expecting it to be in a folder called Zombies and.
Right.
So here is a zombie character.
All right.
And where is he getting this from?
So if I just click on controller, animator, controller, it looks like it's just laid out.
So presumably our meshes.
There we go.
Yes, there's the zombie.
All right.
And what about the animations?
That should be a folder called animations.
There we go.
These are the zombie animations.
OK.
So down into prefabs, then we're just going to basically drag a zombie into our scene and then over
in the scene view.
And I'll just change back to shaded temporarily.
I'm just going to position this zombie somewhere.
Rotate him so that he's actually looking at the player.
There we go.
He just stood over there.
Now, at the moment, he looks a little bit dull.
That's because of the materials that are being used.
So if I just click on this character's Z character, zero zero one can see the material and it's just
using a standard.
Now, it's only just one texture.
There's no normal my pocket map or any of the other stuff.
So we can easily just switch over to mobile.
And on that.
All right.
And then suddenly these fits in with the background.
And so what this character will need is some kind of an animator.
There we go.
And we've even actually got a character controller on this one.
That means as long as I'm selecting this zombie character, I can move over to the animator and we can
see we've got a whole bunch of animations.
Well, we probably don't need this many animations to be on this.
So I'm going to create my own animator controller.
So right click, create animator controller.
Just call it zombie.
On the zombie character, Alex, just click and drag this into the controller and we go now start finding
some animations.
Well, I'm going to do I'm going to temporarily lock this on the meta window so it doesn't go away.
So he always stays like that.
And then that allows me then to select other things without losing access to this.
So then I can go into animations.
And the first thing I want is a walk animation for click on, walk over to animation, can see what
this looks like.
It's going to look like this.
Just make sure that this as loop time enabled can also see that it's got some kind of root motion by
the look of it.
And let's drag and then walk into there.
OK, so that that's going to be the default animation.
And and in fact.
We probably don't even need an attack on the nation.
We just need this war, really.
And so if I just take a look at this through the simulator, let's just see what this looks like.
Oh, he is still in place, but now we can see him kind of just stood in place, sort of walking.
At the moment, I think that walk is a little bit too fast.
So I want to slow that down a little bit for coming to my alma mater, the animal walk.
We have a speed.
OK, if I want to slow this down, I'll go below one.
So if I say zero point seven, it will slow it down a little bit.
Venus, a bit better.
And it looks like a slow sort of shuffling zombie.
You can, by the way, switch between these top.
So for example, I press play and this one and then switch over to scene.
You can also see the character inside of the scene view actually on the meeting.
All right, which I think is fine.
And now what they want to do is actually get that zombi to start walking toward my main player.
So first of all, I want something that it can target.
I don't want it to walk directly into the player.
The White House can look weird.
I want it basically to walk in front of the play.
So where we have our main camera is right click, let's choose 3D object in the cube.
All right.
And that's going to place this cube.
Strike this forward.
And I just want to scale.
So it's not so big.
Maybe something like that should be fine and just drag this so that it sits in front of the player.
All right, so it looks like this could actually drag that further down toward the ground.
And.
Yeah, OK, that's fine.
So we'll call this a target,
and I want that attached to the main camera.
So wherever the camera moves, this target will move as well.
Now, I certainly don't want to see that target, but I do want it to have a box collider that is a
trigger by.
I'll just switch this off so that you can see what I've created.
And by having the trigger, it means that whenever an object actually walks into this box, collider
area is going to set something off in script.
We're going to know that we're getting attacked by a character.
Now, as I say, we don't need a machine renderer.
And instead of just switching off the mesh renderer in Mobile, because we still technically got a material
attached.
It's better to right click and remove that component altogether.
And that way, it will save any unnecessary draw calls.
OK, so all we need to do now is get Zombi character to walk toward this target.
I think I put my scripts folder in mobile game resources.
OK, so I'm going to right click choose create new C sharp script.
Now, call it enemy mode one using mobile devices.
It's best not to use too many scripts.
If you can get away with using maybe three or four scripts, that's a lot better than using 30 or 40
scripts, simply because the processor has to keep open in each script and run in things like the update
method at the start method.
And it just takes a lot longer to do that.
It's only got one script that it has to run the same method on that's going to make it so much faster.
OK, but this one's necessary because I need to attach this script to the enemy.
I can't use the main because that's attached to the main camera.
OK.
So what we want to do inside of this is we want to get this character to move towards the player.
So we actually want to manipulate the transform using a vector three.
OK, vector three is effectively an X, Y, Z.
All right.
Each of these vectors.
So let's find out what we can do with a vector three.
So if you go to help and scripting reference, this is going to open all of the necessary scripting
that's attached to unity.
We can type vector three.
And then if you click the first one.
All right, this is then going to show you everything that you can do with a vector three.
So it's going to give you a big list of everything, which is great.
And if you're not entirely sure what you want to achieve it, because you can just read exactly what
these things are doing.
What we're going to look for is something called move towards.
OK, there it is, move towards.
So it calculates a position between the points specified by the current and target moving no further
than the distance specified by max distance Delta.
OK, so in other words, it will move between its current position and the player's position.
So if I just click on this, it's going to show you exactly how to actually write this.
It's going to give you an example is right.
OK.
So it simply needs to transform, need to speed.
And in the update, we're simply going to use this.
OK, we're going to create a new new variable called step.
They simply are going to be speed multiplied by time Delta time.
So in other words, it's constantly updating and then it's transformed up.
Position equals effect to three to move towards, transform, position, transform, target position.
And then the step, which is the move towards OK.
So let's do that.
So first of all, I need access to that player target.
So public offsite transform, we'll call player targets.
And I'm going to need some kind of a speed, OK?
So I'll make this public so you can change in the inspector of type float.
We'll call speed.
So I'm just going to save this.
And when you attach it to the zombie character.
And we got I got my two slots and let's take the target and set the speed at something like one.
OK, and it's going to be in the updates, what we want to do is effectively create this step.
So that create a new variable.
OK.
So you can simply just type float, create a new variable.
So you you describe the type of variable to create Nicollet step, which is going to equal speed multiplied
by time Delta time.
OK, so in words, it's constantly moving forward.
Each and every frame.
And then we're going to take the zombies current position.
So transform top position equals a vector 3.0 move towards.
And then inside of the brackets, it's going to require the current position to target position and
then the max this distance delta, which you start.
OK, so I'm going to say transform the position as the zombies position.
Then I'm going to say player targets, top position is where it's going to head towards.
And then we finish that off with step.
All right.
That's it.
That's how easy it is to get one object, to move towards another object.
It's going to save that.
And just wait for that to compile.
And now we're going to test this out.
OK, so we could see the zombie now walking toward me now at the moment is walking straight through
one of those tombstones and he's also walking in mid-air.
All right.
Which is not good.
Notice that he does stop right in front of the player, which is exactly what I want to go over to the
scene view.
We can see the zombies.
They're still doing his walking animation.
And so that definitely works.
But it's not the best solution for a zombie, OK, simply because he's he's walking straight through
these tombstones.
It's going to be great for some of the other characters.
So we're still going to use this script.
We're going to do something slightly different for zombies a little bit later.
But this script that we've created is going to be great for all the types of creatures.
All right.
So we're going to put a few of those in in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.