Placeholder Image

Subtitles section Play video

  • What is up?

  • Guys fought here here from awesome dudes dot com.

  • Whoa!

  • Haven't said that in a while.

  • Anyways, Before we start creating anything, I am going to preview the game that we're gonna create.

  • So I'm gonna hit the play button and you will see now that we have our warriors, that they will fight each other.

  • Don't mind the buttocks that you can see from the character.

  • So you see the enemies chasing us in trying to attack us.

  • Actually, he hit me.

  • Pay attention to the health bars at the top, left and top right corner.

  • And by the way, I can hold the shell like this.

  • When I hold the shield, he is not able to attack.

  • And now, when I lowered the shield, he won't be able to attack.

  • You can hear the public behind in the back and let me just up the bottom of it.

  • You can hear them cheering.

  • They like when blood is spent.

  • Anyways, I'm going to attack the enemy.

  • And as you can see, I am dealing more damage because, hey, I don't want to lose in the game that I'm creating.

  • I don't want to embarrass myself And when his help gets to zero, basically, I have to give him two more times.

  • So one more time back.

  • You see?

  • Now he is that.

  • And while I have one and the enemy's health is zero, as you can see at the top, right corner.

  • Basically, this is the game that we're gonna create.

  • We have Millie battle systems.

  • Something we did not do before.

  • We have enemy.

  • Aye.

  • Aye.

  • That enemy can detect where the player is, and it will chase the player.

  • Also.

  • When the player goes away a little from the enemy, the enemy starts chasing the player again.

  • So let's start treating this.

  • I'm in a new project.

  • Let me close this one because I don't want it to be open.

  • Let me close it like this.

  • So right, click here.

  • And finally it's closed.

  • Anyways, this is our project here.

  • We have our samples, and this is a new three project by the waist.

  • You're simply going to go and create a new three D project.

  • Name it.

  • However you want to name it.

  • I named this one warrior fight game.

  • This sample scene, I'm going to change the game plane just so I like to name things correctly and we're going to import the assets.

  • By the way, the assets and the complete project are available for you to Donald Link is in the description below.

  • So select all of these assets model sounds, textures.

  • And you I and simply Dragon drop them right here.

  • Inside of unity.

  • Off course.

  • It will take a moment or two for unity to load all of this.

  • You know the procedure.

  • It takes some time to important three D assets And, uh, yeah, while we wait, I can seem to you or we can stop the video.

  • Let's actually try to sing it.

  • No, I I'm just getting going to stop you Come back when everything is finished.

  • Finally, unity took mercy upon us and it has imported all the assets and we can start building our game.

  • The first thing that I want to do is create the terrain or the ground where we're going to stand for that.

  • I'm simply going to right click here in the hierarchy panel and go under three the object and create a simple cube while this is artery.

  • Now, of course not this cue.

  • We're not gonna stand on a cube.

  • Actually, we are.

  • But I'm going to resize it and I'm going to call it ground for the skill X.

  • I'm going to see 100 for scale White 0.1 because I want to make it.

  • You know, Tin like this.

  • I don't want to make it.

  • You know, Lar, I don't know what's opposite of 10.

  • Don't judge me.

  • Anyways, I'm going to say here Z 100 as well.

  • While this is what we have is going to be artery.

  • Of course it is not pretty at all.

  • I don't want this whiteness tearing my eyes apart.

  • So if you pay attention here inside of the folders or the assets that we have important we have textures inside of textures.

  • We only have this grass texture If I open, this is the grass that basically this somebody took a shot in his backyard.

  • Anyways, what we're gonna do here is we are inside of the textures.

  • I'm going to right click and create a new material.

  • So here it is, right?

  • Click and creates again.

  • It's right.

  • Click and go under.

  • Create and material.

  • This is what we want.

  • And I'm going to call this one ground material and we're going to apply on the ground.

  • So now I can drag and drop this on the ground.

  • And this is how you make game objects look cool.

  • Basically, because pay attention to our ground.

  • It's white.

  • If I put this material on it, it's still wide, though.

  • But what I can do for example, this I can change the color to know red or dark or silver or what?

  • Ever.

  • But I can also drag and drop this grass inside of this albedo or albino.

  • I don't have my hell until here it is.

  • So if I take here as you can see, I have the grass and if I drag and drop it right here, it will this play that grass while on our ground.

  • While this is how you make things look good in unity and in three D.

  • But there is more to these materials and shakers Now, this is the first time I mentioned cheaters.

  • So what are Shader is basically a shader determines how that material or the texture that is applied to that material looks like.

  • So if I take here, pay attention, I have the standard Shader.

  • This is on the dropdown list right here.

  • So here it is.

  • I'm highlighting that with my highlights Will.

  • So when you click out that it's a drop down list and you can play with all the different shade er's you have built.

  • And of course, there are others that you can import from the assets over.

  • These are built in what I like to use this one unlit texture, and you see it's already a little bit different.

  • It's a little bit darker, so the grass looks a little bit darker in comparison.

  • Do what it looked like.

  • A moment go.

  • And I encourage you to experiment with these shader so that you can see their effects.

  • Not every shooter will make your material look good.

  • Maybe some will look bad.

  • Others will look better, but you can find that out if you experiment.

  • So, for example, if I go here, I don't know nature and say speed tree.

  • Maybe this will not make it look good.

  • Well, basically, it's a little lighter, and some shooters also have other fields here where you can add a texture, you can have a normal texture.

  • Now I'm not going to go into that.

  • That's a different topic, and I don't know too much about it.

  • But basically, when you combine these sections like a normal map, another texture, some other texture that come along with it, you make your material look or the game object that has the material look good.

  • Anyways, what you need to do is simply experiment with these.

  • Just experiment, tried him out and see different effects that you will get.

  • And that's how you learn the best.

  • Now moving forward, we have our ground.

  • And again, the scale X is 100 Z's 100.

  • Why is 1000.1?

  • Why?

  • Well, because the attention if I said the why, for example, of 100 I don't want this.

  • What the hell is this?

  • You see, we don't want this.

  • We only want our ground, so we want to make it look like a ground.

  • That's why I put the scales so that it's not too large on the white access.

  • So moving forward.

  • If I go back in assets and models, we have the arena here in side off the Models folder.

  • So in the Models folder we have the arena.

  • If I click here.

  • This is our arena.

  • If I drag and drop it, here it is.

  • This is the arena now, of course, it's too small.

  • So we need to resize it.

  • Make sure it is positioning 000 for X, Y and Z and I'm going to call it Battle Arena.

  • So this is the name of the game object and the scale for X, Y and Z is going to be 25 25 25 25.

  • And while our this is our arena, it already has materials applied on it.

  • If you click on the drop down list, you'll see all of these different game objects that are put together to make this arena.

  • If I deactivate some of them.

  • So let's try activities.

  • You see the effect if I deactivate him while they are gone.

  • So that is another thing if you can experiment.

  • But basically these are just three D models put to get put together to create this battle arena.

  • You can see here we have some people's spectating or whatever.

  • Yeah, this Wieder look at that weirdo.

  • Yeah, these do that.

  • Probably up to something.

  • Anyways, I don't know what I'm saying.

  • But this is our battle arena.

  • Now moving forward, we are going to import our character.

  • And here he is our warrior.

  • Now, one thing to note is this is a headless warriors If I drag and drop in here and if I go to him while this is a headless warrior like a headless woodsman.

  • But of course, we are going to make him with head.

  • So I don't know how you see had what's opposite of headless hand hand on us.

  • I don't know.

  • Anyways, this is our game objects.

  • What I'm gonna do is first of all, I'm going to take and rename itself from Body Underscore zero.

  • I'm going to rename it to war year.

  • Next, we need to apply this head on end.

  • So if you pay attention to the head now, it's too big.

  • We are not getting way.

  • We're not gonna do this to him many bit.

  • Did you do the head licking that?

  • We're not gonna do this to him.

  • We are going to resize the head a little, so I'm going to resize it.

  • Let's say here head is 111 actually, no.

  • So the head is gonna be 1.51 point five and 1.5.

  • Exactly.

  • So 1.5 for the head.

  • This is totally fine.

  • And we need you select the warrior click on this dropdown list.

  • Do you go through all of the elements that make him or took his body parts?

  • So click on the warrior than this.

  • B I P 001 click on that drop down list.

  • And again you have B I p 001 pelvis.

  • Click on that one.

  • And let me just resize this year.

  • Then we're gonna go under spine than spine want and spine to man.

  • This model is killing me.

  • Then we have the neck and right here we have the head.

  • So what you can also do is in the search bar.

  • If I take the highlight tool here, you have the search bar in the hierarchy panel.

  • You can also select the search bar and you can type here, for example, head and it will find it for you.

  • It's this one right here.

  • B i b 001 head.

  • So this is the part of the body that we need.

  • So now we're gonna drag and drop the head right here.

  • Normally, we don't have to do this because under models come with the head.

  • But this model is like this.

  • So what I'm gonna do is I'm going to resize it or actually reposition it.

  • Something to say.

  • Zero point 016 This is going to be for the X for the wind's gonna be 0.0 one to you and for dizzy It's gonna be negative.

  • Zero point.

  • Let's say here I was gonna leave it just a zero Just as you leave the sea at zero and I think his head is all is also still too big.

  • So yeah, this is OK.

  • And let's take here and resize the handle a bit So the scales gonna be point for seven for X Y and Z I think now it's okay.

  • So when you select the head said the scale to point for seven that is 0.474 x, y and z The position X X is gonna be negative 0.274 and why is gonna be 0.12 and yeah, this is where our head is going to be exactly, And it looks good.

  • Looks good, Actually.

  • Looks like it's already built on him anyways.

  • As I said, we're not gonna do this that often because most models come with the head.

  • But this one is like this and what we can do or yeah.

  • Anyway, select the warrior now.

  • And what I'm gonna do is I'm going to click on this ad component here, and we are going to filter for character controller.

  • This is a bill in controller that comes with unity.

  • Safe.

  • I selected here again.

  • It's under add component and filter here.

  • Character controller.

  • As I said, this is a built in controller, and I don't know if you can see the green things around him.

  • So, yeah, I turned off the ground and the ballerina so we can see this capsule thing around him.

  • Basically, this character controller comes with a collider and also comes with a rigid body in it, so we don't have to apply these things.

  • This green thing that you can see is a collider that's around our player.

  • So what we can do is we can reposition it, so I'm going to put it on my 0.96 and for the X I'm going to leave it, Z, I'm going to leave it.

  • A radius, however, is gonna be 0.25.

  • And while I you see the radius, it will resize that collider.

  • Now it could be a little lower.

  • I know, for example, points to one.

  • Yeah, and you can see now it is around our player well around the middle of him.

  • And this is, as I said, the character controller that we are going to use in order to make him move.

  • And by the way, let me just put him like this.

  • So if I put him like this and if I hit the play button, actually, where's my camera?

  • He is standing still.

  • Now, even though we have a rigid body, we have a velocity in our character controller.

  • We still need to apply gravity on him.

  • So we need to apply gravity and in order to apply gravity.

  • Basically, we do that the eye script.

  • So it's time to get our hands dirty.

  • Let's go back in the assets and right click here and create a new folder which I'm going to call scripts inside off the scripts folder we are going to right click and create our bullet here.

  • Move script.

  • And by the way, before we continue, what I'm gonna do is go back here in assets and right click and create a folder.

  • This one is going to be our pre fabs and click here in the brief lapse and drag and drop the warrior so bad.

  • This is our warrior prefab now, so we don't have to worry about deleting this game.

  • Object from the scene and doing all of this from beginning.

  • So if we go back in the script, we have the player Move Script Dragon, Drop it on The warrior and now hit Apply here so that that change applies to do the prefect.

  • Now, one thing I want to get out right now, I like when I go and spontaneously have things that I need to explain why we need to hit apply to make that change apply to the prefab And if you're watching my tutorials probably heard me sing that life 1000 times Well, this prefab right here is basically now the original game object off this warrior that we have in the hierarchy.

  • So let me just take it.

  • So this warrior here in the pre fabs folder is the original one.

  • This one right here is a copy off it.

  • Any change?

  • We apply to this copy.

  • For example, if I go here and if I attach an audio source component, pay attention here.

  • I have attached in audio source component on the copy in the hierarchy.

  • The original one, The warrior here in the pre Fabs folder.

  • He does not have that audio source applied on him because we attached that one on the copy.

  • If you want to have the original, have this out your source because you're attached it.

  • You will need to click on this apply.

  • And this apply applies that to the original prefab, which is right here.

  • Here it is the original prefab in the pre fabs folder.

  • So if I select that warrior prefab in the pre fabs folder, it has the audio source component attached on him now.

  • But the attention out if I go here to warrior and remove and this is the warrior in the hierarchy, the copy if I now remove the audio source component, the original still has the source component The audio because we did not hit, apply but pay attention to the difference.

  • Now, if, however, I select the warrior inside of the pre fabs folder the original one.

  • And if I go here, for example, and filter for a rigid body component And if I applied that rigid body component on the original, what do you think?

  • For the copy, it will have the rigid body applied because we applied it under original in.

  • The copy will simply follow because it's a copy of the original.

  • But if we apply to the copy, then we need to click apply to make that change.

  • Applying to that prefab, the original one as well.

  • So if I removed now from the warrior Prefab, the original one, we also don't have it on the copy prefab.

  • So I hope this clears things out.

  • If not, ask what is not clear in the comments but low.

  • So let me go here.

  • Actually, this is from the previous one, the one that I have previewed it.

  • So going forward, this is the new one that we're going to code from scratch.

  • Let me just click here and hold enter to give a little bit space.

  • So what do we need for our player move.

  • First of all we need are private character controller and I'm going to call it shar controller like this.

  • Not character but char like this short for character.

  • We will also need an animator.

  • But we will do that later on.

  • We also need here public float movement speed which is by default three and pay attention.

  • I said it's to be public, which means it is editable in the inspector panel.

  • And what do I mean by this?

  • When I see it is editable in expect inspector battle.

  • That means the public variable is visible here in the Inspector.

  • Pay attention here.

  • Now you see, we haven't right here.

  • Let me click on the highlight tool And here it is.

  • So we have it.

  • It's right here.

  • Which means we can manipulate this valley by set here value five.

  • Now we have the value five, not three.

  • So if I put it back at three, it is three.

  • Basically, the value that we put here in the inspector panel will override the value that is here.

  • So we have the movement speed.

  • We also have our public fold gravity.

  • This is what I was talking about which is 9.8.

  • This is the gravity in real life as well.

  • We also have a public flown a rotation.

  • So rotation speed which is gonna be equal to 0.15 after we also have our public float A rotate degrees per second, which is gonna be equal to 180 degrees per second.

  • So these are the variables that we need to get started.

  • And the first thing that I'm gonna do use inside of the awake function.

  • Of course we have the start, but I'm going to change it to awake if you are also following my materials.

  • You know that I like to initialize things in a way function because the order of execution goes like this.

  • When we run our game, this is the first function that is called the second function that is called his on enabled this one right here.

  • And this is the second function and the third function is start.

  • So start is the third function.

  • But by default.

  • When we create a project, we have start an update off course we can you start for initialization and in some cases it is better to use start over awake, for example.

  • And I know somebody will ask.

  • When is that case?

  • Well, if you are initializing something in the awake function and you need to get a reference for that, then initialize it in the awake.

  • But get a reference in the start function.

  • This goes for example, if you select a player in the main manual, you initialize the player in the game placing in awake, but you need to follow it with the camera than in the Camorra.

  • Use the code that will find the player in the start function.

  • We will have examples for distance of modern tutorials.

  • Don't worry about that anyway, Something to see here.

  • Char controller is equal to get component character controller and what we're basically done with our character controller.

  • What is the next thing to do is go here in Crete.

  • Void, move.

  • And this is a function that we're going to use to move, which we're gonna call in the update.

  • And here we're gonna have moved.

  • So what are we going to do here?

  • First of all, we are going to test if input get access.

  • And here we're going to say vertical like this is greater than zero.

  • Which means if we have either present the up Hiroki or the W key on our keyboard, because if I take here quickly, the highlight tool and this is the coordinate system.

  • So here we have.

  • Why here we have X and here we have Z because this is a three D game and basically up on the Y is plus down is minus on the X axis to the right is plus, which means the positive sign and on the left is negative.

  • And for the Z, forward is the positive and backwards is the negative.

  • And basically hear this we are testing if we are touching the vertical axis, which is the y axis, that's the vertical axis.

  • But we're going to use this to move our character forward and right here below were going to say else if input get axes and here we're going to say vertical.

  • If that is less than zero, then that means we're going downwards and debate a clear picture.

  • I'm going to use here print and I'm going to see the value is and I'm going to see here.

  • Plus and we're going to use this input and verticals that you can see the output actually off this what this value will be.

  • So if I go back here in unity and let me go into the council, then clear it.

  • So if I hit the play button, pay attention.

  • Now, as long as I'm not pressing anything, it will be zero.

  • But when I start pressing So I started pressing, actually did not.

  • So now I'm going to start pressing and I'm pressing the up Hiroki, and this is what we have.

  • Let me just go here because it happened so fast.

  • It's in the update function.

  • And it up these every frame in a second.

  • So pay attention here.

  • This is where I started to press and notice the values 0.4 than 0.96 then 0.14 than 21 and 31 up to one.

  • So it goes from zero up to one in these increments that we just saw.

  • So 0.10 point 150.2 son and so forth.

  • You get my point and for the negative.

  • If you press down, that is the S ky or the down Arrow key you will get from zero to negative one.

  • And you saw the increments.

  • It goes slowly from zero up to one.

  • If you want to go directly from 0 to 1, then you will use get access.

  • A raw get access raw has the same exact effect it will detect when you collect.

  • Or actually when you press the up pero here the w key or when you press the S ky or the down down a rookie.

  • But when you press the upkeep and w will return from 0 to 1, but we'll go directly from 0 to 1.

  • It will not go in these increments.

  • And that we just saw you can print this and see for yourself.

  • Now, one other thing that I don't like about this code is this right here Not the word worked a call, but instead, me hard coating values.

  • This is something I don't like to do.

  • So if we go here in unity and go back in the project that mean sides of the scripts folder, I'm going to right click in Crete a new script and I'm going to call tax so tags.

  • And here I'm going to double click it.

  • We're not gonna attach it on any game object, And I'm going to remove this public class declaration.

  • So what are we going to do?

  • What?

  • Why?

  • Why did this go right here?

  • So what are we going to do within our classical?

  • First of all, I'm going to create here a public class called axes.

  • And here we're going to have a public constant string.

  • And I'm going to call this one Vertical.

  • So vertical axes, which is gonna be equal to vertical like this.

  • And we're also going to have a public constant string.

  • And this one is going to be horizontal.

  • So Hori zon Till axis, which is gonna be equal to horizontal, as we can assume, because we're gonna have vertical and horizontal.

  • Now, don't mind these red errors that I have this because my computer was open for such many time or for so long.

  • So I have to close visual studio and re open it again to make this actually work.

  • So now when it's open, bam!

  • Here it is.

  • So now everything is working like a charm.

  • As I said, I don't like hard coating values like here, because if we use this on two places or even Maur.

  • It can happen that I misspell something because if I type vertical with lower case V, it's not gonna work even though the word is the same.

  • So capitalization needs to be the same.

  • And when we use it like this, when you when we declare it in a single place, we can simply do this.

  • We instead of typing and like this, we simply say here axes that vertical axis.

  • And Ben, this is it.

  • And here we do the same thing axes, the vertical axes and back.

  • It's the same exact thing.

  • Except here.

  • We haven't in one place and notice here, this constant constant will not change.

  • Same like in math.

  • Now you don't have to be imagine years, do you know that?

  • But basically, if I do something like this, if I say axes, that vertical axis is equal to me.

  • Changing it.

  • It is not going to work because it's a constant anyways, moving forward.

  • Now we're detecting if we touch or if we press the up Iraqi or the w key and hear if we press the down arrow key and the S ky So if we press the up Iraqi will want to move forward.

  • And in order to do that, we're gonna see here.

  • Vector three move direction is gonna be equal to transform forward.

  • What the hell is this?

  • Transformer forward?

  • Well, if I have over it says the blue axes off the transformed in the world space in order to paint a clear picture.

  • If I take my warrior here inside of the scene and I zoom him on him Do you see this blue axes, this blue ever Oh, that I'm taking and dragging him.

  • This is that axis indicating the forward.

  • So no matter where he is, because we can rotate him.

  • If I do something like this and I rotate and you see now forward is this way, not the way where it waas.

  • So basically it was this way forward.

  • But when we rotate him, you saw what I mean.

  • And this right here the transform forward is telling us the move direction is to move forward.

  • So now we're simply going to say move direction that why minus equals gravity multiplied with time got dealt a time in order to apply gravity.

  • This is what I was talking about in the beginning.

  • So when we attached actually the character controller, I said that we need to manually applied gravity to our character, and this is how we do it.

  • This is how we apply gravity by subtracting from why gravity multiplied with time, Delta Time.

  • Why time that dealt the time?

  • Well, because we are calling the move function in the update.

  • And if you want to smooth out things because update is called every frame or actually once part, Frank, if we have 60 frames in a second, that's 60 times in a single second dysfunction will be called, which means this one will be called as well because we're calling it in the update.

  • Now.

  • If we subtract from why gravity on Lee, which is 9.8, that's a very, very it's gonna happen very fast.

  • It's a huge number, and we're subtracting that every frame 60 times in a second.

  • That's why we need to multiply with time that Delta time and time dot delta time is the difference between each print.

  • So how many times you took to go from last frame to the next one?

  • That is the delta time, and it's a very low value.

  • And this Why on that, that is the reason why we use it to you.

  • Smooth things out.

  • So moving forward we have here applying our gravity.

  • The next thing to do you simply call our character controller and move in order to move our game objects.

  • So we pass here the move direction.

  • This is where we want to move multiplied with the movement speed multiplied with the time that delta time to smooth things out again, smoothing things out with time that delta time.

  • Same reason as what I explained right here.

  • And this is we're moving in this direction, but we are multiplying that with the speed movement in order to speed up the movement.

  • Now what I'm gonna do is here for our negative or actually, when it's a lower than zero, that means we need to go backwards.

  • So I'm simply going to copy these lines of code and pays them right here.

  • And since we don't have transformed backwards, we have forward.

  • But we don't have backwards.

  • I'm simply going to use the negative.

  • So I'm gonna say minus transform forward, which is simply the negative afford which is what is negative for up forward, it's backwards.

  • Think of it as opposites.

  • So this is going to have the same effect except backwards.

  • And here we are using move direction, which is now backwards, multiplying that with the moon speed.

  • Multiply that with the time that Delta Time, and we can test it out if I go here and one thing, another tip from me.

  • Take notes when I say these tips if you want.

  • For example, if this is where you want your camera to look, for example, in your scene or when you were on the game instead of using the camera and positioning, and I know I don't know, it's 10 20 Turney position, for example, and this is where that position is or dragging it and dropping it simply.

  • What you're gonna do is position here the view, how you want it, where you want the camera to look in the scene, select the main camera in the hierarchy and on Mac, hold shift and command on windows.

  • It's control, command and press F.

  • So when you press F so now pay attention where the camera is exactly seem please, where we are looking in our scene.

  • Now that we have that done, I can hit the play button and I can test this out.

  • So we have the player in Walla.

  • I'm pressing the w keen on pressing the arrow key up.

  • Iraqi and W is moving forward.

  • I'm pressing the back a wrong key and non person.

  • That s key.

  • He is moving backwards.

  • So a lot this works.

  • The next thing on our agenda is to rotate our game object or the player.

  • So let me just go here.

  • And this one is for the move.

  • And here void a rotate.

  • And this one is for the rotate, which we're gonna call right here in the moves.

  • We're going to see a rotate like this because move is called in the update and we can safely call rotate below it.

  • Or you can simply take the rotate outside and you can call it here.

  • It does not matter into the exact same effect.

  • So in the road eight, we are going to see here Vector three, which is the rotation underscored direction by default.

  • I'm going to see it's equal to vector 30 This is the default one because Vector 30 is a short hand for writing Vector 3000 for X, Y and Z because we're gonna detect input again.

  • We're going to see if input dot get axes and we're going to see here axes, horizontal axis If that value is greater or actually, if it's a lower than zero And here we're going to see else give input that get access and again here axes the horizontal.

  • Now here, we're gonna test if is greater than zero, and we're gonna do the following.

  • So if it's a lower than zero, that means we're pressing the A key again.

  • This is the coordinate system.

  • This is the horizontal axis, meaning the X axis.

  • Going to the right side is the positive.

  • Going to the left side is the negative.

  • So if we press the a key or the left Hiroki, we're going to the left side, which is negative, which means this right here will be lower than zero.

  • If that is the keys, where something gonna see here, a rotation direction is going to be equal to transform that transform point or actually transformed direction.

  • And here we're going to see vector three dot left.

  • Now I'm simply gonna copy this and paste it here.

  • And you can assume that here is gonna be vector three dot Right?

  • And by the way, this one is gonna be separate.

  • So we're not gonna do if else or else if and why?

  • What did they give me?

  • This axis here, anyway?

  • Here.

  • I'm going to see if it would get access.

  • We are not going to use if else simply We're gonna do if and if, Because we can press these buttons.

  • Seven.

  • Tennessee.

  • So if we press the eight year too geeky, that would cancel each other out anyways.

  • Moving forward.

  • What is this transformed direction?

  • Well, if I hover over, it's gonna see Transforms the direction from local space to world space.

  • What is that?

  • What is local space?

  • What is world space?

  • Let's go back immunity to explain the local space.

  • If I dig the warrior and of course I'm gonna go in the scene first and zooming on the warrior.

  • This is my warrior game.

  • Object.

  • If I right click on him and create an empty game object that I'm going to tag here with this orange or yellow tag.

  • You see this game object right now inside off are So he's basically inside of our game object our hero If I moved him here and now he is in front of him.

  • If I take the ex senator zero take the white said it at zero.

  • Take busy 70 Now he's back at the center and his center is around his warrior player that he's his local access.

  • That is the local access, his own origin.

  • So his own origin of that demanded with origin.

  • I mean, where that game object goes when we set 000 for X, Y and Z, or when we reset the position on the transform, Where does he go?

  • That is his origin or keys, local axes, local position.

  • That is, if I go here, you see transform direction from local space to world space.

  • But what is the world space will world faces all of this Here You see everything that we see here.

  • So where are Cubans are actually our ground where our battle arena is where our player is that his unity's world space and this is where we are moving When we move this character, we are moving him in the Unity's world space.

  • That's where everything happens.

  • So we are transforming the direction here, which is Vector three left.

  • And if you go here a short hand for writing negative one for exes, you're zero for y and Z and the right is positive.

  • One for X zero for four.

  • Y and Z basically were transforming this into the world space, and this will transform it into the left side off our game object inside of world space, and it will do the same thing here for the right direction.

  • So now that we have the input for the left in the right direction, we have here the rotation direction right here, we're going to say, if input that or actually now we need Thio, rotate our game objects that were going to say if a rotation direction is not equal to Vector three that zero.

  • So if it's not equal to zero, that means that we have here input, and that's the reason why I'm setting it here to be equal to zero, because we are resetting it every time.

  • If we don't reset it, Reese at it, reset it here, then the value that we get here will stay the same.

  • And here it will stay the same every single time.

  • So we need to basically reset it here to zero.

  • So Vector 30 But if it's not equal to Vector 30 that means we got input here.

  • So what we're gonna do you simply we're gonna see transform.

  • A rotation is equal to Quaternary in that rotate tow words and this will rotate from rotation.

  • That is, from the transform rotation to rotation is gonna be quite attorney in.

  • Look, rotation is gonna be a rotation direction in the given speed and are actually the grease and that the grease is gonna going to be a rotate degrees per second multiplied with time that delta time.

  • What the hell is going on here?

  • Teacher, what are you doing?

  • You are driving me crazy and okay, let me just gone down.

  • Calm down.

  • I'm gonna not driving.

  • Driving crazy anymore anyways, you see here transform rotation is gonna be equal to this rotates tow words.

  • You see, he rotates a rotation from towards too.

  • This is from.

  • So it will rotate from this rotation to this rotation in basically these or this degrees.

  • But this is clear it will rotate from the current rotation has towards this tradition right here.

  • Now, look, rotation basically creates a rotation with a specified forward and upward direction.

  • Basically, this will do the following since we are rotating around the Y axis.

  • This is the Y axis and it will create a rotation around the Y axis and the forward will be placed on the Y axis.

  • Basically, if the Y rotates over here.

  • So now why is here?

  • Then the forward will be here.

  • You get my point now.

  • The reason for that is because let me take our warrior.

  • You see here, pay attention.

  • Pay attention to the blue axis of this on right here.

  • If I rotate him, you see, you see how the blue access rotates along with him.

  • Basically, this is what we're doing with look rotation.

  • It will look at the rotation from the Y axis.

  • It will basically rotate it from the Y axis, which is what we want.

  • We want to rotate on the Y axis, and this is the degrees by which we are rotating the game objects or rotation degrees per second that we added Here 180.

  • Multiply that with the delta.

  • Time to smooth it out.

  • If we don't smooth it out every frame we will rotate exactly 180 degrees.

  • And it will be fast really fast.

  • So if you want to test it out, you can do it by simply doing this right here.

  • Basically, let me just do it just to test out and show you the facts off the smooth time.

  • So if I go here and if I run the game so pay attention out if I rotate.

  • This is what happens when you wrote it like this.

  • You see, this is what happens because we're rotating so fast.

  • This is 180 degrees for a second.

  • If we don't multiply with Delta time to smooth it out.

  • Then you saw the effect exact Same thing will happen for this year if you don't multiply without the time.

  • Exact same thing will happen here if you don't multiply that with time that delta time.

  • But if I hear the play, But now that we're multiplying that delta time, pay attention, I'm gonna press, right, right?

  • Actually, so right, you see how he's rotating now smoothly and left.

  • And he's rotating, also Smoothie.

  • So now we can move and rotate.

  • So now our game object can move and rotate at the same stunt to see moving and rotating in Walla.

  • So I'm pressing left and I'm pressing right.

  • And he is rotating towards the direction where I am pressing what This is, how we move a character and how we rotate character.

  • So the next thing to do is to make the camera followed the player.

  • Of course, we also need to animate him, but using the camera to follow him will be much easier because there is less code involves.

  • I'm gonna write a book here and go on Creed and See Sharks script, and I'm going to call this one camera follow, and I'm going to show you two ways.

  • How can we make the camera follow the player?

  • Because this is programming.

  • There is always more than one way to solve a problem, so select the main camera and drag and drop.

  • The camera follows script on the main camera, so Dragon dropped.

  • The camera follows script on the main camera.

  • I'm simply going to double click it in.

  • Open it here in Visual Studio A and let me just bag the class and we don't need here that many lives of code.

  • Basically, we need the following.

  • So we need a private transform which I'm going to call target.

  • And this is going to be our player.

  • We will get to it in a moment.

  • We also need a private vector three offset.

  • Now it's a private variable because I don't want it to be accessible in other classes.

  • But I also want it to be visible here in the inspector panel because I want to edit it.

  • So in order to do that, we're simply open square bracket and type serialized, serialize, field and wall are so open square bracket close square brackets in between type serialized field.

  • Because now, if I go back in unity, that private variable will be visible here in the inspector panel.

  • Bam!

  • And here it is right here, and you can simply remove What did I do?

  • So let's go back here.

  • And you can simply let me just hide this so you can simply remove this line of go to test it out to see for yourself.

  • If you remove it, it will not be visible in the inspector panel and more so moving forward from the awake function, not the start.

  • I'm going to get the targets I'm going to see.

  • Target is gonna be equal to game object.

  • Find the game object with the tag player tag, Doc transform because we're getting the transfer property again.

  • Two things.

  • Two issues we have here.

  • First of all, this right here is a no, no, I don't like it.

  • So we need to go back here in our tags and we're gonna greet a public glass cold tags.

  • And we're simply going to have a public constant strength.

  • Clear underscore tack, which is gonna be equal to player.

  • This is the first thing in the first issue.

  • Same as with our axes.

  • And I explained that.

  • Why?

  • So if I go back here, remove this and we're gonna see tags.

  • That player tak it's the same.

  • Exactly.

  • Now, in order for this to work, you need to make sure that your player, the warrior when you select him, and right here you have the tag property in the inspector panel.

  • You see where I'm pointing with the mouse?

  • You can click on it, so let me just hide here and you can click on it and you need to select the player tag by default.

  • I think it's from unity.

  • Five version and upwards you have here, Dag player he by any chance you don't have it, you're gonna click here on ad attack.

  • So click on add tag.

  • And now here we see dag and list is empty.

  • Click on this plus button.

  • So this small pause button right here that I just pointed thio.

  • So when you click on it, it will open this short window.

  • You thought you will type here your tag, click, save.

  • And then that tag will be available to you.

  • So, uh, now that you created attack, you're simply going to select the game object.

  • Go here and tag it.

  • So click on the tag.

  • You want to take it and pay attention, please.

  • Please.

  • This is a tip.

  • So note it down.

  • If the name here is player with P capital keys P, it needs to be the same exact name right here.

  • If you type here lower case be, it will not work even though it's the exact same words of capitalization Also needs to be in order.

  • This is really important.

  • So now we have a reference to your player.

  • We have the offset here inside of our or actually below the update.

  • We're gonna create void follow player, and we're going to call this function in side off the late update function.

  • So no update but late update function.

  • And what the hell is a late update?

  • Well, let me first explain we have the update function and we have the fixed update function.

  • Update function is called every frame in a second.

  • Basically, if we have 60 frames in a second that it will be called 60 times.

  • Update function is good for moving a game object using the transform property or the character controller as we are already doing and also for getting input which were also doing here is we're getting input.

  • We do that in the update function.

  • Fixed update function is not called every frame, but it's called in a fixed number.

  • Frame intervals.

  • What does that mean?

  • It's basically called every third or fourth frame, and this right here is dependent or that is dependent on if we go under, end it and go here under project settings and then time If you take a look here, let me just clear it with the pencil.

  • You see here this fixed time step it's set to 0.2 It's dependent on that time.

  • Basically, fixed update function will be called every 0.2 off a second.

  • And it's good for physics calculations.

  • So if you want to move your game object using the rigid body, you will do it in the fixed update.

  • But what the heck now is the late update.

  • Well, late update is same as update.

  • It will be called every frame, but it will be called after the update finishes.

  • So if we have something like this, for example, I don't know into a B and C and we want to see here C is equal to a plus B.

  • This calculation will be already done and we can use the value of C in the late update, and it will be this value here calculating a plus B, and it will give us the value sea, and we will be able to use that in the late update late.

  • Something is really good for using code or typing out code that will be for example, like this, you know, Did you follow the player?

  • Because we are moving the player, as you can see here in the update.

  • So in the update, we will calculate his position and he will arrive at that position.

  • So now, in the late up, we already know where the players position is, and we can follow him smoothly now, in order to follow the player smoothly.

  • What we simply need to do is we need to see transform that position, our own position off the camera.

  • He's equal to target play year.

  • So the target, which is the player transformers you can see right here.

  • And we're gonna use the player, transform to you, transform direction, or actually transform the point.

  • And we're going to transform the point off set.

  • So off said, and basically, let me just go here, I'm gonna name it, offset position not to be confused with that rapper offset.

  • It's upset position.

  • What is transformed Point you see here transforms position from local space to world space again, basically same thing as what we did with transformed direction.

  • It will transform this point from the local point off the target, but pay attention Here.

  • Pay attention, please.

  • We're using here Target, which is the players?

  • Transform as you can see here.

  • So it's the players transform.

  • It will transform that point from the position off the player.

  • So from the position of the player, it will transform that point.

  • And it will transform it from his local position to the world position.

  • And if we test it out right now, the beauty here is that our main camera now has these visible in inspector variables for the offset X, Y and Z And what we can do when I hit the play button, you will see now where the camera is is basically here.

  • But what

What is up?

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it