MAKE your FIRST FPS in UNITY - 3 HOUR COURSE

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up youtube this is dennis ponyta for tutorials.eu in this video you are going to learn how to build a first person shooter from scratch using unity and c-sharp so if you don't know the c-sharp basics or the unity basics you should definitely check out our videos up here and they will teach you those basics but if you have some experience in unity already then this should be the perfect next stepping stone for you to become a real game developer because we're building this beautiful little first person shooter here and you're going to see all of the features that you need to get there and if you think that this is a cool video and it's nice to build some games and get an entire course for free a three and a half hour long course for free then definitely hit the like button and subscribe button really helps us out and also subscribe to our unity specific channel where we only upload game development videos and that channel really needs some love so hit the subscribe button there as well and now let's get started building this first person shooter game so let's go ahead and create a new project and this time we are going to use the scriptable render pipeline therefore let's select universal render pipeline this one here and then give it a name i'm going to call this one zombie fps and now let's create the project so let's look at what this scriptable render pipelines or high definition pipelines means all right so this chapter we're going to use the scriptable render pipelines scriptable render pipelines allow developers to write how unity renders a frame in c sharp instead of using the built-in render pipeline like we've been using in the past chapters which does not permit modifications currently there are two srps so the hdrp so high definition rendering pipeline and the urp which stands for universal rendering pipeline let's look at hdrp first so high definition rendering pipeline is designed for high fidelity graphics high definition and improved lighting high definition materials and for the highly seeked ray tracing feature but also being low performance and needing directx 11 at least so definitely a pc that is newer so this is not something you would use on a mobile phone so urp is designed for high performance being the standard for vr mobile and simply having the broadest range of platforms and is really easy to use with the trade-off of losing visual fidelity and limited lighting so which one is the right for you deciding that boils down to the nature of the project here are a few questions to help you determine which pipeline is best for you do you need your project to be optimized and perform well on wide range of devices then you should use urp or are you aiming to release your project for high-end platforms then you should use hdrp and as you saw we are going to use urp which stands for universal render pipeline so when you come into your game you will directly see that it has a bunch of assets directly inside of them you see here a bunch of folders materials presets scenes scripts and all of the good stuff so if you go to your scenes folder you will see that it only has the sample scene which is this scene that we have in here inside of our game so let's scroll in a little bit you see here we have a couple of example assets and they look pretty nice graphically they're pretty good you see here very detailed graphics and this is something which is quite fine if you have an okay pc but if you have a poor pc and you would replicate this and have a bunch of different assets then it will become a little more difficult to edit it so i highly recommend to upgrading your pc if you feel like this is too slow for you but for our project we're going to use assets that aren't too heavy on your hardware because i think that not everyone has a super strong pc and powerful pc which is why i decided to use rather low graphics assets which don't look as amazing as they could but it will make sure that it will work on even older pcs out there quick pause the video that you're watching right now is just a fraction of the entire fps course and of course you're not only learning how to build a first person shooter but also make it a multiplayer game so you're going to learn a bunch more things than in this youtube video it's a seven and a half hour course and you can not only get the course but you can currently also get the book with a 50 discount definitely check out the link in the description below to improve up on what you're building in this video and become a real multiplayer game developer so in your assets under example assets you will find that you have a bunch of urp materials here so these are urp enabled materials and non-urp materials will not work here so if you were to take or to create a material here let's go ahead and create one i'm going to call this one non-urp and the shader would be the default the standard one you see you get this magenta color and if you use it somewhere it will not work properly so as you see even though it's set to white or whatever color i'm setting here it's not going to work properly so materials have to be urp enabled which means here the shader has to be set to universal render pipeline and there you can select different options for example an unlit option and then suddenly it's fine and you could change the color here okay so it has to be a universal render pipeline asset okay so then on top of that let me get rid of this material by the way on top of that if you go to your project settings under edit you will also find on the graphics that the scriptural render pipeline settings are set here okay so here this file is something that you have under your settings with a bunch of options that you have here so here are a couple of different settings so we can look at those you see universal rp high quality low quality medium quality and so forth and then if you go to your package manager you will also see once it's loaded that under your unity registry you will find the universal rp here as well in my case it's version 11.0.0 the universal render pipeline is a pre-built scriptable render pipeline made by unity all right so that's exactly what we're using for our project all right now let's go ahead and get rid of those assets because we won't need the example assets in our project we are going to instead use our tutorials eu assets so let's go over to our assets here and i'm just going to drag in the tutorials.eu assets you can find them assigned to this lecture so just download this tutorials eu assets zip file unzip it and drag it into your project there you will find a couple of assets for example the characters we are going to use two characters one is going to be the first person player and the other one is going to be the zombie so let's drag the zombie in this will be the zombie that we're going to use and this one will be the first person player here that has a weapon plus two arms here so that's just a prefabs for the character you will also find a little more here for example the environment so here if you want to drag in the city so let me reset its position so this will be the city that we're going to use for our game as you see here we can then walk through the city with our first person character and then shoot zombies once they appear so you see it's rather low poly what i'm using here and i'm using that specifically in order to make sure that this is going to work well on your machines so if you want better graphics definitely you can anytime download nicer assets from the asset store and import them into your game alright so let's set up our game scene in the next video welcome back in this video we are going to set up our game scene at least the beginning of it so let's go ahead and go over to our assets and then inside of the scenes folder let's create a new scene i'm going to call this one game and now let's go over to the scene i'm not going to save the sample scene because i didn't make any changes well many changes i added the city to it and got rid of the default stuff but actually it's going to be fine because i don't need the sample scene all together i could even delete it at this point so let's get rid of it and now inside of our game scene let's go ahead and first of all add something to it because if we look at it right now it's pretty empty and that has to do with us not having added any materials to it if you look at it in your urp default assets materials you will find the skybox material and you can just drag it into your scene and look at it in the game view you see now you have the sky box even though you don't really see it in the scene window but let's look into the sky boxes and what they do for us so a skybox is a six-sided cube that is drawn behind all graphics in the game so a big box where you would stand in the middle to simulate the surroundings without actually having to create a sun or clouds manually taking away a lot of your work for you and also your computer using textures like the one on the right called a cube map which is one of the more typical ways to do it implemented inside of unity as a material type skybox slash cubemap but also having the option of using six images taking the component like so where you have the front back left right up and down or hdri more typically used in 3d software being basically a 360 degrees image but there is one more that unity includes which we all use on by default and that's the procedural skybox a special kind of skybox that changes on the rotation of your directional light in some cases that's the best option but it's customization not being as user friendly since we don't need to modify it but would like to have the adaptability of the procedural sky we'll be using this one and why not the urp included one and it just looks nice and i think it's fine let's continue with it we've imported a lot of assets using the tutorials eu on the score assets folder and in this video we're going to look at those assets so let's get into it first of all you will see that we have this characters folder and we already opened it a little earlier so here you will find 3d models for example the two 3d models that we have the fps character as well as the zombie character then we have a couple of animations in here we have materials first of all the skin of the arms and then the zombie material which indicates how the zombie should look like then the prefabs which bring everything together and of course the textures that are also important for our zombies for example here we have the zombie a in our case but you see depending on which texture we're going to use the zombie is going to look differently then we have the weapons folder in which we have our 3d model which is this weapon here it has also a black material which makes it look a little nicer and then we have this prefab which is basically going to be this weapon so it's pretty small let me change its size here let's scale it up and let's go over to the weapon so there we are this is going to be our weapon here which looks pretty good i believe and we can use this weapon for our game quite well so then inside of the assets folder we will also find the environment you have a bunch of 3d models here which are as you can see balls containers even trucks and so forth so you can use those in order to build your own map however you want it so feel free to create your very own map using for example this dirty ground and so forth there are a bunch of materials that are and part of this environment so we're going to use those you see you can also just use those prefabs instead of the 3d models and they will be good to go then you of course need to position everything correctly so that is going to look fine and then we of course also need to have textures for our 3d model so that they are going to look nice so concrete asphalt third and so forth are the different assets that we have here and then we have an entire city which is a big prefab so the environment prefab that we prepared here in case you don't want to set this up by yourself so i'm going to reset its position and you will see that this is going to be the city that we're going to use we saw it a little earlier but this is basically going to be what we're going to work with and you can of course if you want to adjust this city if you just want to make changes to the city where you for example move around certain blocks so for example this building here you could move this building around if you wanted to add more buildings and so forth so feel free to make the changes that you want to the city or even build an entire city by yourself depending on what you prefer by the way while we are going to use this city in the end in the next couple of videos i'm going to show you a couple of tricks and show you how you can build this city from scratch okay so we're going to use the assets that we have available building the city so you don't have to be able to do it already you can of course try it but i will show you a couple of tricks in the next couple of videos that will really help you with that and you can of course also just skip those if you're not interested in the city building part and jump directly to the player lecture instead now looking at our weapon prefab let's go over to our weapons folder prefabs here you will see that the weapon only has a mesh filter and the mesh render as well as a material so it's free for us to edit it now to add a script to modify the weapon so that it does what we want it to do and in the next video however we're going to focus on the city building blocks a little more so see you there welcome back in this video i would like to start building the city from scratch we're not going to build the entire thing in this video but we're going to get started with some fundamentals that will help you to then build the rest of the city as you like so let's get rid of the city asset that we have here and let's go into our environment here in the prefabs you will find a bunch of prefabs that we can use and the one that i'm going to start with is going to be this road asphalt so let me drag it into my game and let me reset its position okay so now it will be at 0 0 over here and this is where my rope will be and i think it's fine looking good but now let's make sure that we extend this row to so that we have a bigger road piece so to speak therefore let's drag in another rope piece like so and now you will see that this roll piece is in at an entirely different position so let's reset that one as well and now let's move it around so we can of course try to position it correctly here at this point but there might be an overlap and it won't look as good what we can use however is going to be v and then we can move around with our mouse to find the order so hold your v key and then you can snap you see you snap the edge let me do it once again so here zooming in i press v and then i can snap it for example to this corner over here or to that corner over there and now let me duplicate this as well piece and now move this one with that corner over to the other side here at the top for example and now if i'm looking from a different angle it will be probably a little easier so like so now let me use this one once again press the ctrl w in order to duplicate it press this v key and make sure that it snaps directly towards this edge let me duplicate it once again hold the v key and well maybe not this key corner but this corner right here and let me snap it over there so this is how you can snap your prefabs so that they are going to be at the same levels and that they are fitting perfectly together because otherwise it would be a pain we would always have to check what kind of positions do they have and so forth but this way we can just drag prefabs into our project and position them accordingly all right now let's add some more pieces to it so here let's look at our street let's say we want to use this piece here and we want to add it into our game but it's another side so something like this here but then of course i want to make sure that this corner is going to be perfectly snapped in there all right there we are so that worked out flawlessly now if we want to use that same piece for the other corners we have to rotate it first so let's duplicate this piece here this outer corner and let's first of all move it over to this edge here but now i would like to rotate it because this doesn't look correct right so let me go to the rotate tool here and here you can use control for precise snapping okay so hold the ctrl key and for example turn it around by 90 degrees so there we are now let's go back to the movement tool which is this button here or the w so okay now we have moved it to that corner so first of all move to your rotation tool in my case it's the e button this allows me to rotate hold the ctrl key and then rotate while holding okay so let me go back to the movement tool let's duplicate this piece let's move it over here and now let's use the v key to make sure that we position the item correctly and it doesn't seem like it's correct now okay this looks a lot better and now i just need to rotate it so in my case press the e key hold the ctrl key rotate it on the green axis so that it fits your liking let me rotate a little further like so and it should be good to go and now the final edge so let's do that once again ctrl w to duplicate then move it around you can also hold by the way the hold the ctrl key while dragging and it will also snap so snap it in correctly press the e key for rotating or press this button here at the top drag this green circle drag it a little bit holding the ctrl key even further and until the point where you are happy with the results so now we have the beginning of our intersection here now at this point you might wonder there's so much stuff already in my hierarchy well that's something that we can fix by creating a empty game object here so let's create an empty game object let's call this one streets here streets or roads something like this either way would be fine and now let's make sure that this piece is reset so that the streets are in the center and now let's drag all of them in there except for the directional lighting we don't want it to be there and of course the main camera neither and let's drag it into our street so now we can just close our streets and our hierarchy will still be workable with or viewable properly okay so now let's extend our road a little bit therefore let me for example take this road asphalt side piece here let me see is that what i want yes i think this one will be fine so let me take that let me drag it into the game you see it's a little off from the rotation perspective so let me rotate it by 90 degrees like so now let me snap it using the w key first of all for moving then holding the v key to now snap it correctly to this corner let me see like this and then always double check if it is in the right level so here the y level should be correct otherwise if it's just a little bit off you see then the streets won't be correct so this looks a little better all right now let's go ahead and duplicate this piece let's move it over to the other side then let's rotate it by 90 degrees so here like so and well actually 180 degrees not 90. so like this then what we can do is we can take another road piece like this one here let's duplicate it and move it over here using the ctrl key while we drag it this way we are going to snap it so now what we can do is we can take those three pieces here and we can duplicate them drag them over holding the ctrl key so we're snapping them duplicating once again and dragging well duplicating once again and dragging so this is how we can now create our street pieces and we could even go ahead is let's say we need more so let's use all of those here we could duplicate those hold the ctrl key and drag it over so this way we are creating a pretty long street okay now let's just make sure that all of our asphalts are actually part of the street like so okay okay so now let's add buildings and let me see which one looks more like a building wall with window wall b well it doesn't seem like we have a proper building let's add let's add this wall garage here okay so let me drag that in there and now it won't look great because it's not positioned correctly so first of all let's press e to rotate it and then let's rotate it by 90 degrees like so let's make sure that we have the using tool at the moving tool and let's move it over like so and now let's use the v key in order to snap the corner correctly now you see here that it snapped it but it's not on top of the street so i'm not super happy with that so let me snap it again and maybe even the interior part like so let me snap it like so all right this looks a little better even though now you might say let's move it a little further to the left there could be an option so here unfortunately the snapping tool will not be your friend so you can well you can still snap using the control key but the v key will not be your friend in this case even though as it seems they are not entirely the same with here maybe they are yes they are but then you have to be unprecise with your values here so something like -12 if you do it manually and the x position seems to be at 7.6 for example something like that then it seems to be good okay so either you make sure that the garage is really on top here or the alternative would of course be that you make sure that the garage is like so that's fine as well but then don't forget to also add maybe a garage piece here so let me snap it over or i mean street piece of course let me snap it over so that it's underneath here so it doesn't look off because here we wouldn't have anything underneath it so these are some minor changes that you might have to make after you build your map let's say with an alpha version of it all right and now let's say we want to have this wall painted let's drag that in there let's use the v key once again and let's snap it right next to our garage here and now let's use the wall a with door this one here let me drag it in there i would like to have the door in front of me so let me rotate it press the e key rotate by 90 degrees press the w key move it with snapping make sure that we snap this edge directly or maybe even the top edge that seems to be fine or top corner so now we have the garage we have the door we could even add a window if we wanted to so let's see if we have a wall with a window so here wall a with window let's drag that in there let's rotate it by 90 degrees and in my case i didn't use the control key this will be better so now the w key for moving move it around a little bit now look if the edges are correctly connected there we are let's snap it together okay so we have a wall front now and now you could go ahead of course and design your city as ever you like maybe you should also add rooftops here so a wall roof either the detailed version or the undetailed version let me use the detailed version here let's rotate it once again so here let's rotate it by 90 degrees like so and now let me snap it as well so here not the rotation snapping but the movement snapping so let's use this corner let's duplicate this piece let's move this over here with the v key pressed duplicate once again and now it's use this edge and put it there and then finally another one duplicate it let's move it over not with the right one but with the blue one here like so and now let's snap it in correctly like so so you see unity is really a beast when it comes to helping you with its tools to create this little street here now of course you have a bunch of other assets that you can use fences you can use the truck here so let's add the green truck into our great game here so let me put it in like so it will block the streets for example that would be fine of course you can also use it in order to snap it in so now the wheels will be inside of the ground so whatever you want okay so that is how you can build the overall level but now let's look at how we can decorate it correctly that's what we're going to do in the next video welcome back in this video i would like to talk about decorations as well as what your map can tell about your game so it can actually tell a little story even so let's look at this so let's look at this truck here and maybe let's actually drag in this flat truck over here okay so having this you could expect that some truck owners or some people thought okay this is where the zombies are coming from so let's block them for example okay so they didn't block this tree because they wanted to for cars to still be able to pass through here but they blocked those other streets so that no one can come from their side or from that side so let's move this truck around a little bit so that it's actually positioned correctly something like that should be fine now what we can do is we can add some scrubs so here let's add a little tree small like so and then what we can also do is we can add a bit of well some bricks here so let's add some bricks in here like that maybe okay so now you could say okay people tried to make a fire here maybe even or something like that but they put together those bricks let me duplicate that and something like that and they try to make a fire in the center here not with this ground but more like with this scrub here so even though this is not perfect but this is a little bit what you could tell about this this map now or what you could say okay now this is where we are creating an atmosphere for our game where it's not just elements that are in our game not just game objects but they actually tell a little story okay so that's something that you could see here then we could go ahead and add a little bit of a traffic light here i don't know what would be the order something like this probably well not on the street let me move it around also using v here let's snap it around like so okay this looks a little bit like it i guess so that should be fine then we can add where is it so further up i believe some barriers here so let me add this barrier into my game so here towards the end maybe even like so then somebody came along and blocked the street with a barrier and maybe a def a second barrier and a third one so they blocked the street like this they tried to block it and then even some stone barriers you could move those around and try to position them accordingly okay so let me put it in there well this probably isn't that great let's also put it behind it in the streets so let me find a good spot doesn't seem like it maybe using the control key will be a little better okay so you can now go ahead and build your level like this you can add cables to your game they're not very detailed but let's say people tried to use cables in order to hang something okay so let's reposition this cable like so and then let's rotate the cable even further using our keys here once again to rotate now like so all right so yeah you can see a bunch of options here what we can do maybe we can move it a little further even like so yeah so now there's this cable hanging well yeah you can see a bunch of options that you have even with this limited amount of resources that you have here so the game objects that we have here it's not insane amounts of objects but you can still build some cool stuff here all right you can even go ahead and add a little bit of a fans here so add the fence over there let's turn it around like so by 90 degrees okay and now let's move it in like that let's make sure that we have a ground there maybe not a street ground but maybe dirt instead so here road third center let me add that in there let's make sure that this dirt is also positioned well so here this edge should be something like that maybe underneath yeah this looks a little better so now we could duplicate this dirt move it around like so duplicate once again yeah and step by step our game is getting a certain shape and looks a little more like a game not this point you can also make sure or you should also make sure that your streets are going to be at your street level okay then your walls let me also put the walls separately so let's create a new empty game object in here create empty and i don't want to put it in there but actually outside of it you see why it becomes difficult to do it via right click you can still do it here create empty let me create an empty game object for walls or houses something like this would be okay or buildings maybe even instead of houses build things and now let's put all of those walls in there like so into the buildings the details there we could say and let's create another one and by the way i forgot to position it to zero zero zero oh that's that's tricky okay let me go back let's make sure that i position it at zero zero zero let's reset it and now let's add the walls in there let's get them into the buildings the same for those ones we have any other walls here something this one here and now let's create decorations decorations let's make sure it's reset here and now let's add the details in there like so all right and now this three small maybe it's also decoration road third center well we could say this is part of streets like so yeah step by step it looks more and more like a map okay so okay so as you see you have a lot of options when it comes to how you create your map and this is actually quite difficult because sometimes you want to build a map in a way where it just creates this atmosphere right and atmosphere is created by lighting it's created by what is in the map and how things are positioned in the map okay so this year if you put a bunch of bricks next to something you could assume that they were before maybe on the truck okay so you could duplicate these and put the other ones on to the truck so that it looks like okay they were on the truck then they fell down for whatever reason and yeah basically you're painting a story by building your map and adding these little details will then make a whole difference which creates a scenery which can create a bunch of images inside of the head of the player okay so especially in our zombie apocalypse game this is going to be a very important aspect all right so in the next video we're going to see how we can limit the directions the player can go and that's going to be something quite important because you want to make sure that the player can't get outside of your game and suddenly fall off or something like that so see you in the next video welcome back in this video i would like to talk about some very important parts of your map and these are the limitations as well as basically just areas where your player cannot get to okay so let's make sure that we take for example these parts here and also the roof duplicate it then i'm going to drag those over there on to the other side i'm going to make sure that i'm snapping them correctly and now let's actually rotate this whole bunch by 90 or by 180 degrees so let me see like this and it's not actually that working that well this way so let me just drag it okay so this should be fine now okay so now we have limitations on both sides and something that you will notice is that if you look at one of those walls that you have here the buildings is that they have a mesh collider so they have a collider which means we cannot walk through them which is very important of course but now let's create some more colliders here so what i want is i want that the player cannot walk past this area here of course the player can jump on top of this stuff that you can see here but now let's actually limit him so let's add a couple of trees in here so i'm going to position them using the move tool and the and let me put them in here then let me duplicate this and put the other tree a little further down there another one over here another one over there so now maybe also some three three scrubs like this let's make sure that they're positioned at zero zero duplicate put it next to it so while this is not perfect it's still fine right so we can go ahead and maybe add another window and house here or wall with a roof so let's duplicate this and let's drag those over here duplicate once again drag over there we can do the same with this garage here duplicate move over there duplicate move over there so now of course you see we're missing the ground so we could of course move this ground underneath duplicate move it over here duplicate move over here so now it looks a little more like okay there's for some reason now there are trees okay let's make sure that maybe we don't have uh concrete underneath it but more of a green on the green ground so here grass for example okay so let's drag in the grass let's make sure that we position the grass accordingly then duplicate the grass duplicate once again like so and let's make sure that it's positioned i'm going to overlap here it's fine for this purpose so now we have grass there and what we can now do is we can now add a huge wall that will stop us from passing it okay so here let me add those all to decorations like so and now let me add an empty game object and i'm going to call this one wall alright so now let's add this wall let's duplicate this by the way and we can also rotate it a little bit so that it looks a little cooler another one like this rotate it a little bit because otherwise it looks like it's just too clean okay so now we have this wall that i created let's move it actually it's going to be empty so let's make sure that we change its y and x position oh okay so it's jumping over there let's get rid of the z position as well okay so where i want it to be is i want it to be over here okay so let me drag it over there and it will look a little better once i give it a component so let me give it a box collider here for example okay and this box collider should be a lot bigger okay so let's play around with the scale here and the x scale of let's say 20 should be good here and the y scale of 20 so now we have this big wall let me move it up something like this and let's move it over here so now we will have inside of those trees we will have this wall we can even give it a gizmo let's add a gizmo here so that we can actually see it inside of our scene a little better so now we have this wall let's click on it and this wall should limit the player from walking through so the player can walk into the trees but he cannot walk any further than that so now you could of course block his vision a little further by adding some more trees over here so let's duplicate this tree and let's position a couple more trees in here it can be a little more random you can even rotate them if you want to so let's rotate well not this direction but this direction like so let's rotate the trees a little more so that they don't look all the same okay so this should create an effect where the player let's assume so the player is not going to have this flying position as we do but the player is going to be like at this level okay so that's how high the player will be and then he will walk over here and he will try to pass through but he can't okay so he will be blocked by our wall that we just created okay and this is also going to be a good spot for zombies to spawn because the player cannot see where they're coming from so they're coming from the trees and let me by the way make sure that i'm duplicating the grass down here so that it looks a little better it doesn't look like the trees are on the gray ground or something like that okay so now if the player who's limited to not go any further than this for example you will only see trees well in the background there you could of course add well actually in our game we will have a horizontal which will make it a little better i believe but yeah overall you see now the player will be limited he cannot go any further and this is going to be the spot where suddenly our zombies are going to spawn and they will come from here they will maybe pass through the edges here or they will come from the other side and then the player has to shoot them okay so this is something that you now have to consider at every single point where the player can run out of your game and glitch through your game so to speak glitch through the walls so really make sure that you build a map which is consistent but also tells the story and at the same time has limitations where the player cannot walk through because your map just won't have anything else to offer there's nothing cool that surrounds the game anywhere outside of this little map that you're building and it's even good if you build something that the player cannot access that is going to look like this is a real map that doesn't just end at the edge where we're walking towards okay so you could build the street further a lot longer towards the this side you could build more houses here even though the player might not even see them correctly and so forth all right but that is something that you would now need to do towards all sides so yeah see you in the next video welcome back in this video i would like to give you a little challenge and that is to actually finish the map okay so please go ahead and make sure that you build your own little map and always when you make changes make sure that you save your scene because otherwise your scene will be lost and the beautiful map that you will have built will be lost make sure that you clean up your hierarchy as i haven't done here for example i need to add this to my decorations same goes for the grass here i could actually even put the the trucks as decoration in there and then once i'm done with that i need to save my scene so what i would like you to do now is to finish a map if you feel like it of course if you don't want to build any maps in the future and you will always use pre-built maps or you have somebody else who's going to build your maps for you then you don't have to learn it but i would really recommend that you do it by yourself to get a feeling for it so make sure that you build a little map that looks good you can of course get inspired by our assets that we have here the city that we built you can see that this is just one way of doing it we're limiting the streets here we have some lighting we have some sidewalks we have well a bunch of trucks that crashed into each other some limitations some more trees so more of a world that looks like something went wrong here okay and we have two stories instead of just having one story so a little higher houses and even here at the top you can see some iron laying around and so forth so just go ahead and be inspired by what you see here build your own map make sure that there are walls so these hidden walls where the player cannot pass through as you will see here well if you check out our city you see this collider here as well as there so these are colliders that are making sure that there are sidewalks but the player cannot pass through okay and then there are cables between houses and so forth so see this as a little challenge it's fine if it takes multiple hours it really depends on how much time you want to invest into learning this into creating a nice map and once you're done building it feel free to share it with us and if you use other assets even better these assets are for free but of course you can use other free assets or even paid assets just make sure that the assets that you're using follow the same design language so for example now we have these kind of assets which look semi-realistic but with poor quality let's say but then there is low poly which can look pretty awesome and if you combine the two it would look off so don't make this mix where you're mixing different kind of assets into one game quick pause the video that you're watching right now is just a fraction of the entire fps course and of course you're not only learning how to build a first person shooter but also make it a multiplayer game so you're going to learn a bunch more things than in this youtube video it's a seven and a half hour course and you can not only get the course but you can currently also get the book with a 50 discount definitely check out the link in the description below to improve up on what you're building in this video and become a real multiplayer game developer so first person shooters i think we all know what they are and we all probably played one at some point i mean they've been around since the early 90s with wolfenstein 3d and doom we have our character and we look through his simulated eyes and control his actions throughout a game world but what is a fps playable character made of well a lot of games do use the approach of a full body character using the entire character and animations to represent the player especially in online focused fpss but even there your main character so the camera your view is using almost always only sees one thing and that is your character's arms and whatever he's holding since rendering the rest would just complicate development and worsen the performance of the game i mean in an fps the only thing you'll see are your arms anyways a good percentage of games don't even have more than just the arms especially in action-focused offline games making development way easier and more dynamic since nobody restrictions are there like we see here in our game we'll be using the same approach since for now we'll only need the arms we won't be adding a body but who knows that may happen further down the development in our case the assets we include have separate meshes with their respective materials in the correct hierarchy also included is an animator component and a shoot animation we'll be using but no animator yet nor any scripts so let's start working on it in the next video welcome back in this video we are going to take care of our main character our first person character so to speak and therefore as you can see i have gotten rid of the city that i built in the last couple of videos and i'm just using the environment here and that's the city so just feel free to use your own city just make sure that the center of it is going to be at 0 0 0 or otherwise you can of course drag in our city our environment that we prepared but also make sure that its position is reset so that it's going to be perfectly in the center of the map so here this will be the center point and from here we can then start with our main character and all of that so first of all let's go ahead and prepare our player therefore under assets you will find your character and there in the prefabs folder you will find your first person character so let me drag that one in there and you will find that this is what we get our character now we of course need to find a way to make the camera position into the position of the first person player okay so therefore what you also should make sure just in case that you have different sizes i played around with the sizes earlier and this is something you have to do inside of your weapons and here in the weapon prefab just make sure that the scale is set to something around that so here 0.011 for x y and z in terms of the scale okay so now our first person player consists of let's look at him the fps character as well as the arms that you see here okay so the arms they consist of the upper chest with the left shoulder neck and the right shoulder so what we want to do is we want to make sure that this is going to be the view so we are looking through the eyes of the player okay we only are using his weapon and his arms therefore let's go ahead and drag the main camera into our first person character directly into the character in case you get an error here and it doesn't work for you what you can do is you can make sure that you unpack your prefab unpack completely and then you will be able to drag in your main camera so in case this creates an error for you that's how you could fix it so just to make sure that it's going to work for all of you i'm going to right click and unpack my first person player completely and then i'm going to drag the main camera into the first person character like so and that will work totally fine so now if you look at the game this is going to be the current view so let's make sure that our first person player is at 0 0 0 let's reset his position and then let's put him up a little bit so i'm going to use 1.5 for him and now let's make sure that the camera itself is also at 0 0 0 because now it will be at 0 0 0 in comparison to our main character like so okay so now the camera is directly inside of the player so to speak but in my opinion just a little too low so let's tune those values a little bit therefore i'm going to use the following values so 0.35 this is something and this is not for the city but actually for the camera 0.35 so now it's a little higher which is already good then the y position i play around with it a little bit and something around like 0.03 in into the negative made it look a little more natural so the weapon is on your right hand side then your head is a little further to the left so that's how i envision it and then the z position is something like 0.05 so the camera is just a tiny bit further to the front and looks at the weapon just a little bit differently so now you will see that you have clipping here so that the player clipped our weapon how can we fix that well the cool thing is the main camera has a setting and you will find it under projection okay so here the main camera has a bunch of settings that you can set up right and the one that we're going to look at is going to be the projection one and here the clipping planes that's where you can change the values to get rid of clipping so i'm going to use 0.01 here and you will see that the clipping is gone because now it's not going to clip our weapon anymore and that basically fixes the issue okay so if we run our game we won't see much because what we cannot move now we cannot play around and move the character and stuff like that that's fine because in the next video what we're going to do is we're going to first of all look at how we can make our character look towards the direction of our mouse okay so our mouse will move around our view and we will not move the character forward or backward or to the sides yet but we will at least be able to move his view so that's it for this video now your main character is ready you can of course go ahead and make sure that you save your scene that's always a good idea after each video and we can now make sure that we are dragging our first person player into our prefabs folder so you can get rid of your old one that's fine let's get rid of it and let's drag in the new one like so and now let's save it and this will now be our first person player that we can reuse anytime and we also have it available physically all right so see you in the next video where we're going to look at mouse look welcome back in this video we're going to take care of the camera movement using the mouse look so basically moving our character based on the direction our mouse is and the logic behind camera movement is grabbing the axis of the input and applying that to the rotation of the well usually first child object and one that contains the model and the camera but not the root since that's reserved for movement all right so even by using the z rotation things like leaning becomes a possibility let's start implementing that in a mouse look code all right back in our unity project let's go ahead and go to the scripts folder inside of our assets and here you'll find a simple camera controller what we're going to add however is our own script so let's go ahead and call this one mouse look okay so the script will allow us to look around with our mouse which is exactly what we want so now we have to think what is it that we need well we need to get the input of the mouse and we need to know the axis so which direction is it going this is going to what's the left what's the right to stop the bottom so that's something we need to figure out we need to know how quickly we want to move the players so we're going to use a mouse sensitivity here and then we need to transform the player based on that so we need to make sure that the fps character's rotation is going to change based on that so let's get started first of all let's set up the update method so that it will get us the access input of the mouse so float mouse x as i'm going to call it it will be given to us by using the get access and here we use the mouse x axis okay so if you recall if you go to your input manager you will find the different axis and the input manager will allow you to modify things okay so you see the sensitivity is set up already mouse y is set up so here we're going to get the mouse x and mouse y input that's the x axis and that is the y-axis and we get them from the mouse itself so let's use those so first of all we have our x position and we will also need the y position so let's go ahead and add that will be called mouse y and it will get the mouse y axis you need to make sure that you write it exactly this way otherwise it won't work so now as i said earlier we will need the sensitivity so the mouse sensitivity so let's create a public float value mouse sensiti vt pretty long name i'm going to set that to 100 we can modify it later and now we can actually use this mouse sensitivity to multiply it to our inputs that we get okay so here let's multiply that to both of them and now we need to consider that we have this update method right and inside of this update method we want to make sure that this is going to be frame rate independent so here let's multiply with time the delta time which gives us the time that has passed since the last last iteration or the last call of our update method so let's use that for both of them now we need to make sure that we rotate our player and therefore we need to know what we need to rotate right so let's get the player using a public transform here which will be the player body okay so by getting the transform component from our player body which we can then drag in okay so if we save the script we will then find it well once we assign it to something like for example our fps character so let's actually do that so here fps character let's drag the mouse look script in there and now we need to define what the player body will be so you see we can modify the mod sensitivity and the player body so now let's drag the root player into it so the first person player as the body that we want to rotate all right now we can use this in order to actually rotate the player because right now if we play the game nothing will happen because we're not doing anything right we're not rotating anything and that's why we can now use this player body to rotate it okay so there is this rotate method that is available inside of the transform class and we know that our player body is of type transform so we can now apply a rotation to the object to the transform and i'm going to use vector up here so vector 3 up multiplied with the mousex value that i have at this point we can save the script and let's check it out let's see if we can rotate our player at all so you see i can rotate the player but only in one direction right i can only rotate them on the horizontal axis so let's modify our code so that it will work in all directions now in order for this to work properly we need to consider something that is called clamping because we want to make sure that the player cannot rotate down infinitely or up infinitely because this would create a very unpleasant effect for the player so not the character in our game but actual player of the game so let's make sure that we actually clamp the rotation here because this mouse y value is cool and all but it's going to make us sick if we don't clamp it so if we don't limit it to let's say 90 degrees okay so therefore i'm going to need another variable here i'm going to call this one x rotation and i'm going to set it to zero and then i can set it up here inside of my update method i can just set it to the minus the mouse y value like so and by the way if you were to edit you would get inverted control so maybe it's useful for some type of simulation type games so this is how you could set it up here right instead of using the minus here you would use the plus here if you wanted to get it inverted so you could even have an if else statement here checking the settings of the player for example and then depending on that you could then modify well run either the minus equal mouse y or the plus equal bars mouse y all right now we need to change the position of our current character and therefore we're going to get the local u rotation here by using quaternion dot euler which returns a rotation that retains z degrees around the z axis x degrees around the x axis and y degrees around the y axis so now here i'm going to pass the x rotation and for the y and z rotation i'm just going to use zero like so so this will only take into consideration this x rotation that we have added so we call that x rotation even though it's taking the mouse y value because we are impacting the euler float x value with it okay now let's get into clamping so let's have a look at what clamping does so what we want to achieve is that we can only rotate 90 degrees up or down so rod minus 90 for the x value to go up and 90 to go down so that's basically what we want to achieve and therefore we will need to use the concept of clamping so let's take the x rotation that we have here and let's clamp it and it's as simple as using the math f struct which has this clamp method and what this clamp method needs is first of all the input which is the value and that's going to be our x rotation and then the limiting values that you want to use so the minimum and the maximum values so in my case i'm going to say the minimum will be minus 90 and the maximum will be 90 degrees so that's how we clamp all right so now that we have the mouse input that we have the rotation and we apply this rotation to the transform [Music] towards both directions we're good to go so let's run this and see how it's going to look like in our game and we will notice a little challenge here let me show you it will be very obvious in this case so here okay i can move and you see my mouse is moving outside of the screen which is not very pleasant so it's not very easy to manage this way also the speed is in my opinion too slow but this depends on your mouse settings so it highly depends on your mouse settings actually i'm going to change the mouse sensitivity to let's say 1000 and let me run it once again and now i'm good to go okay so now i can rotate i cannot move the player yet but i can at least look around but now let's fix the problem that our mouse is leaving the game scene on this game view in order to fix that there's one very simple line of code that you can use and that is cursor dot lock state is equal to cursor lock mode dot locked okay so this cursor locked mode is an enum which has multiple states it's either locked let's let's look at it actually none locked or confined and in our case locked is what i want to have so here making sure my mouse doesn't leave the game window all right let's save this script and let's get back to unity and let's run it and now you see i'm locked in the game my mouse is locked i can use the escape key in order to get out of it but once i click into it again my mouse is locked again escape in order to get out of it again and then stop the execution now let's maximize and play so that's going to look a little better because it's bigger so there we are now i can play my game and i cannot shoot that yet i can run yet but we're going to take care of all of that step by step so see you in the next video all right so now let's make sure that our player can move and unity has an integrated input being the horizontal and vertical axis these return certain values depending on the key press when we press the w the vertical axis will return one or minus one when pressing the w the vertical axis will return one or minus one when pressing the s key the same goes for the horizontal axis with the a and d key it's pre-set up also to work with gamepad so you don't need to take care of that separately alright so back in unity let's go ahead and take care of player movement therefore i'm going to create a new script inside of the script folder it will be the player movement script all right so let's take care of that we have done player movement before it will be very similar there will be some minor changes however okay so as always we first of all need to get the input and i'm going to get the x and the z coordinate from the axis horizontal as well as vertical we have seen the input manager before right so we are just getting the aws d keys as well as the arrow keys okay so this will be left and right or a and d and this will be w and s or up and down so we get those two and now we can use those in order to move our character so let's create a 3d vector which will be called move in my case and it will get the right position multiplied with x so whatever we defined here as x so whatever we added for the horizontal direction which is saying okay move the player towards the right multiply it with x so if x is negative then he will not walk towards the right but he will walk towards the left so this is the red axis of the transform in world space so it will just move the player towards the right and now we need to make sure that we are also adding a little bit of a twist so that we cannot only walk towards the right but we can also walk towards the front so let's use transform forward and multiply that with z and this will create this 3d vector which we'll now know in which direction the player should move now we can use this in order to move the character but how can we move the character well i don't want to use a rigid body here where i make it move based on physics but i want to make sure that the player just walks without physics okay so with a constant speed so to speak and this regarding physics entirely what we need to do therefore we need to move something called a character controller so let's go to our first person player and here let's add something called character controller this one here so this character controller as you can see it has a sli slope limit step offset skin width and so forth and what it gives us at the same time is going to be this physics body okay this collider surrounding it so we can change the collider a little bit i'd say let's tweak those values just a tiny bit the y value should be a little lower so zero dot or minus 0.35 so that it's a little lower should be good to go in my opinion now you can of course play around with this value as you like okay so let's get back to our play movement script because here we now need to get this character controller so i'm going to create a new variable here called character controller which i'm going to call controller like so and now let's use this controller to move him okay here in our update method we can now move the controller so as you see this is a move method that the character controller has to offer and a more complex move function taking absolute movement deltas that sounds amazing and we need to pass the vector that we want to move towards so let's just move it towards our vector3 here now this would move the character but how about also making sure that we can modify the speed of the character that's always a good idea i'm going to start with a value of 12 here as the default speed and now finally let's make sure that our move here so this is the vector that we're using is also going to be impacted with the speed as well as time the delta times so that it's going to be time or frame rate independent so our game will or the player will be the same speed no matter on which device you're using it and now at this point let's save the script let's go back and let's make sure that our first person controller or first person player gets the script so let's add this player movement to it and now let's add the player or this character controller to it at the same time we can also make sure that we apply all of those changes to our first person player as well as save our scene so that the scene is not going to be lost in case uh unity crashes for example and now let's see so i can now move around i don't have a jump key yet but i can already move around in my game and it looks pretty cool i'd say well getting stuck that's good well i'm not good to get stuck but as you see this game works so i'm not really good i'm i'm pretty fast here the sensitivity is maybe even too fast for me i'm not a big fan so i'm going to tweak the sensitivity here let's use 500 instead and that's how you can tweak the sensitivity in your fps character right in the most look script and the first person player will take care of the movement so the fps character is taking care of the direction we're looking at and the first person player is taking care of the actual movement all right that's it for this video see you in the next one welcome back in this video we're going to fix the gravity problem because if you tested your game a little bit you will have noticed that if you step up on something that the game will push you up so it will let you move up a little bit but then you will stay up so it doesn't pull you down anymore so your character is floating in the air so to speak and as you can see there's no gravity so we went up but we don't go down and in order to change that we are going to take care of gravity which is basically a force added to an object over time with a value depending on a given gravity number making it exponentially grow in speed until it reaches terminal velocity implementing it would be moving our character down with an increased velocity so let's add that to our script therefore let's go back to our player movement and let's make sure that we have a vector3 velocity here velo 30 like this and i'm just going to leave it at empty for the beginning and then i also will need to gravity so i'm just going to use the default gravity that we have on earth so float gravity of 9.81 f which is 9.81 meters per second square that's how the velocity or the gravity is on earth so that's how fast items accelerate so to speak okay and now what we can do is here in our controller player move here we can make sure that our velocity is going to also have a y value that will take the old velocity plus gravity times time delta time so just making sure that it's going to work correctly inside of the update method now to actually add that to our player movement script we need to go ahead and say controller dot move and here we are going to move with the velocity also and because physics tells us to calculate increasing velocity in a free fall we need to multiply gravity by time squared to do that here we need to once more multiply our velocity by time because velocity is already meters divided by seconds if we now add the time delta time then we are going to divide it by 10 seconds square so this will now give us the right timing here so that's going to be the gravity that's how you can implement it manually without using a rigid body and all of that that is definitely going to be relevant for our game so let's run the game and let's see if we can fall down again after we have walked up something so you see gravity is pulling us back down like this all right so that is pretty much it now you know how to add gravity to your game and our only issue is that velocity just keeps increasing indefinitely as if we were in a constant freefall but we obviously aren't so let's add a way to let our scripts know that we are indeed on the ground therefore inside of our player character so inside of the first person player here not the fps character but the first person player let's create an empty game object i'm going to call this one ground check while we're at it we can also give it a little bit of a gizmo here because otherwise we won't see it properly let's also make sure that ground check is going to be at 0 0 0 and here for the y position it shouldn't be inside of the player but maybe a little further down so minus 1.4 should be good because now the square will be inside of the ground so to speak okay because our character if we look at it here it's at 1.5 so it will be just at the edge we can play around with this value later if we're not happy with it in the end so for our ground check now let's go over to our player movement here and let's add another variable here public pool is grounded so this one will know or will indicate whether we are grounded or not so inside of the update method we can use a cool method here so is grounded we're going to set that to physics dot check sphere so what that will do is returns true if there are any colliders overlapping the sphere defined by position and radius in world coordinates so let's just do that now this check sphere isn't very happy because you see it needs a position a radius a layer mask and then there are multiple overloads that we can use but we're going to use the one with those three so we need to set those three up so let's create first of all i transform public transform i'm going to call this one ground check then i ground distance so here ground distance which will be let's say 0.4 f we can also play around with this value and then we need to set the layer so here public layer mask that i'm going to call ground mask so this layer mask by the way specifies layers to use in a physical raycast and this layer mask will allow us to know which layer we are at so now we need to pass those values so let's check past those values here ground check dot position then the ground distance as well as the ground mask that we just set up and then the checksphere method will be happy so now what we can check is if it's grounded and the velocity towards the y-coordinate is less than zero then let's run some code so what we want to do here is we want to change the velocity of y to be minus 2f this will give us a small landing transition of some sort okay so it's not like we are going to have no velocity towards the y coordinate at all this will make the grounding process a little smoother because in the next video we're going to see how to jump as well and this is a little trick to make it a little smoother as well as pressing the player to the ground removes the possibility of floating because we really want to make sure that we're not floating all right now let's save this script and let's make sure that our first person player here has a certain well let's apply the changes that we made and now let's look at the layers because so far we have not really used layers right but there is on one hand the tag but then there is also the layer so the transparent effects layer water layer ui layer and we can now add another layer and i'm going to add it here on the layer six position and i'm going to call this one ground okay so this ground will now be my new layer let's make sure that we add that here and now back in our first person player we need to make sure that the mask is using the ground setting here so the ground mask will use our new layer that we added the ground layer here so let me use ground once again like this so now here we need to make sure that our street is going to be the ground so only if we are on the street we want to use this ground layer okay so really make sure that we change the children here okay we need to make sure that all of the children inside of my street have this layer ground to them because now if we are on the ground we know that we don't need to fall further down so we don't need a velocity that pulls the player down okay so that's one way of doing it of course so you see when you're not using rigid bodies for movement and for physics there are a lot of extra steps that you need to take and now we just need to make sure that the ground check that we're using here is added to the ground check setting so here the ground check of our main character this extra component that we created let's make sure that we are dragging it into our first person player ground check property here by the way make sure that the player itself has a default right we just added the ground but we don't need the ground layer for our player we really just need it for the streets okay in our city now you also might want to add the ground layer to other items that you want to be able to jump on for example those blocks here or for example also the vehicles that you have here the decorations like such as the cars and and stuff like that so add the ground layer to whatever you want to be able to jump on and not use gravity dragging you down for so let's test this let's see if we can actually now be pulled down properly with the right gravity well we have the smooth effect i'd say so it feels smooth how we're dropping down it doesn't feel super awful or anything right okay and now let me check it without maximize on display so here you can then also check your character out and see the y value here the position is at 1.43 and you can see we have a little bit of gravity pulling us down like so and in the next video we're going to see how we can use jumping and then you can see the gravity in action even better so see you there welcome back in this video we're going to take care of jumping and therefore we can use the axis call to jump so here there's this jump access it is going to work in a very similar fashion as we have seen with the horizontal as well as the vertical axis but now we're actually going to use the get button down method to get the jump button so the cool thing is we don't have to specifically define what the jump button is because well it is defined in here inside of unity directly so let's go over to our scripts to the player movement script and we have one big advantage because we have already taken care of this is grounded bullion okay so we already know when we are grounded and this allows us to only jump if we are grounded which is perfect so let's go ahead and in our update method add the following line of code so we are going to check if the input get button down is going to be jump so i have to write it with a capital j here and if the player is grounded so only if those two things are given i want to make the player jump so in here i could do something like velocity y is going to be 10. so now we have a velocity that will push the player up by 10. okay so let's test this let's save the script and quickly check if we can jump in our game already and let's check it out and there we are we can jump even though we jump way too high i would say so this is something that you can definitely now play around with you can test what you like most in terms of which jump height you want the player to be able to jump towards so i can even jump onto this truck here and potentially even jump onto houses which is super tricky because then our player could easily glitch the game by jumping on top of one of those houses and then well get out of the map so to speak okay and we want to avoid that alright so that's something that you definitely need to test every time so let's get out of it here and now what i would like to do instead however i would like to use a method here which will give me the jump height times the negative gravity okay because gravity is pulling the player down and i want to push the player up what i'm going to do there for is i'm going to create a variable so that a game designer could then play around with those values or we can play around with those values later by using float jump height and i'm going to use 2f here so i'm just going to say i want to jump up twice the gravity but in a slightly more complex manner okay so here we have this gravity which is created here but now let's do something similar here where we use the gravity also but the function is a little more complicated so what we're going to do is we're going to say that we want to use the square root so math f dot sqrt which gives us the square root of the jump height multiplied with two times the gravity like so and two times negative the gravity so jump height multiplied with twice the negative gravity and from that we're going to get the square root so this will give us a rather good velocity i would say and the designer can then play around with this jump height value and modify it okay so let's save this script now and test it so there we are let me jump and you see the jump seems to be all right so this is not an insane the high jump this time it looks a lot like a more realistic jump in the game i would say so you can jump up this truck here but only at this point so you cannot jump to the top of the truck maybe you can bug yourself up there somehow but it doesn't seem like it okay so now we have added our jump feature and in the next video we're going to look at the animations and setting up the animator so see you there welcome back in this video we're going to add the zombie to our game and we're going to look at the animator first okay so let's go over to our tutorials eu assets in the assets folder you will find prefabs and there for example the zombie so let's go over to our z scene view here and let's add the zombie just in front of our player so somewhere around here should be good let me also turn it around by 180 degrees something like this and then if we look at it there is our enemy so there's the zombie so let's start the game let's look at the zombie and you see the zombie doesn't do anything it just stands there in the t pose okay so this hands out pose is the t pose because it looks like a t right so now what we can do is we can go over to our zombie and check out what the zombie is made of so the character medium here for example has the mesh renderer and the material so the character medium is just the appearance of the zombie that we have here the the zombie game object is just a parent game object that contains the appearance as well as the root which contains the hip the left foot and the right foot control okay so what you can also see is that your root has an animator okay so if it had no animator for example if you for example only had the appearance of a zombie you could add your animator manually so you can just go ahead and add an animator this way like this okay but i'm just going to revert the changes and now this animator component that you have inside of your game object needs to have a controller the structure is always you have your game object that has an animator the animator needs a controller the controller needs to have animations that it needs to execute okay so we're going to build this up step by step in this video we're going to first of all add a new controller therefore let's go ahead and go to our characters folder and here under animations you will find a bunch of animations and we are going to adjust those later on so these are animations you will see where to get animations later and these are controllers so we have the fps controller which is an animator controller and then we have another one here which is the zombie one but we're just going to create our own now so let's create a new animator controller so right click into the animations folder and here you can create a new animator controller so let's do that and let's call it zombie animator so zombie animator you could of course call it zombie animator controller but sony the animator will be fine as well so now let's open this up and what we will see is something similar to what we have seen before when we created our space invader clone okay so we have the entry state and we have the exit state of the whole animator controller but we're going to now add different states which then allow us to run certain animations as you see here we have a couple of animations ready so the zombie idol as well as the zombie walking and you can also download the zombie run animation that we're going to use you can even double click on it and you will see what's going on in this animation so the zombie run is quite a long animation as you will see so there's a lot going on you have the hips control you have the left oblique you have the right up leg so a bunch of individual body parts and each of those goes through a certain movement okay certain animations so every frame there might be a difference for example for this hip rotation that happens but we're going to look a little more into that a little later so for now let's look at where we can get animations from and how they work so animations are essentially a set of instructions for the correct movement of what's called bones during a set time think of them as literally every other animation from shows or movies or well your favorite video game it's what basically makes the characters move so they can be handmade like these ones where a character gets a set of bones created and then animated moving their body part frame by frame creating key positions so you tell an object to be in a specific position at a specific frame and moving it to the frame in either an interpolated or a non-interpolated way in other words smoothly over time instead of instantly so another option which is what we are using today is to use other available sources of already made animations be it community made like an open game art org or using advanced tools like mixamo which is where we get our animations from so it's this one here the latter one being just an amazing tool that lets you get characters and animations for free you can use them even letting you import your own model and an on-site auto rigger we went ahead and already went through this process and added the animations to the included assets but if you want to try it out don't hesitate to visit the page and do it there so now let's quickly look at mixamo and then in the next video get started using those animations so there is this page called mixamole.com you can sign up for free and then you can find characters as well as animations so here you have all of the different characters that they have to offer for free even jill which is a zombie or one kind of a zombie you can see here jill doesn't have the mesh assigned to her at least that's not loaded but you can see how she's going to look like in a t-pose then you have the skeleton zombie t avalanche and you can then add animations to it so there is our skeleton zombie in its t-pose as well you can now find animations so here and then just run a certain animation for example capoeira so now you see the zombie doing capoeira so you can change the posture and actually you see after a while the mesh is also loaded you can change the step width in this particular animation so now the steps won't be as wide you can play around with the different presets that are here so overdrive is the speed here then the character arm space in this particular case is relevant so really play around with it to create whatever animation you want so for example sitting laughing you will have different kind of settings here so here the funniness if the funniness is insane that the character will laugh a lot more you see here like he grows really insane and loves quite a bit here going crazy if funnyness is less than that you see he just loves sitting there and not going too far back so you can really play around with those values and you see there are tons and tons of animations so here's sword and shield back looks like a pretty cool animation here even though in our case our character doesn't have a sword so we have to well basically also move around here so you see you can even follow the character using wsd or wasd and you can see how your character will be moving with this animation it's a very long animation so there are 49 animations in total for this one animation combo so to speak but it looks freaking awesome in my opinion so then there's also the kaipo era pack which also contains a bunch of different animations not just one so yeah i think you get to just you get the idea of it so make some more amazing tool you can find a bunch of characters for your games you can use them i think they even say that well the rights are reserved by them but you can still use them so you can still use them in your game i think you have not you don't have to pay anything for it even though i would definitely double check that in your case if you want to know but more about it check out the terms of use yeah then you have all of those animations and you see i'm scrolling down and there are 52 pages with animations jab cross idle to push up injured walk left and so forth even here for archers you have animations walking back as an archer sitting in disbelief female animations and so forth okay cool so let's go ahead and use some of these animations in our game so see you in the next video welcome back let's actually use our animator controller in order to set up some animations so go to your zombie animator here the animator controller so on the major dot controller and then you will find this empty animator you should be on the animated window at this point and here you can just go ahead and create an empty state so let's do that let's call this one zombie run like so now it will be called zombie run and now let's add the zombie run motion to it so here you can drag in the motion or you can select it from here so i'm going to use the zombie run motion now let's go over to our zombie and there in the root let's make sure that we are using our zombie animator here so you can drag it into your zombie animator controller here and then let's go over to our game and run it to see whether our zombie is now in fact running so you see well it ran at least for one frame but then it stopped running so it was a little too fast for us to see it and that is because it doesn't loop yet alright now instead of making him run for a short second as we did here so you see he ran for run run iteration and then stopped so instead of making him run let's get rid of this let's create a new empty state and let's call this one idle idle means nothing to do so the zombie doesn't have anything to do he doesn't have to run he doesn't have to jump and none of that okay so let's add the idle animation here from our animations in here so zombie idol will be the motion so the animation the motion for our idle state now what you can also do is instead of creating a state you can directly drag in one of your animations this will create a new state for you so now we have the zombie run animation you see the motion is directly there and our zombie animator what we can now do is we can now go from the idle state to the run state so the zombie will first be idle and then it will run so you can right click into your idle state and make a transition to your zombie run so what will now happen is it will go from the entry state to the idle state where it will run the idle animation and then it will go to the run animation so let's quickly look at that you see first the zombie is idle and i'm just too fast see idle idle and then it starts running so the game is not frozen it's just that it ran the idle animation once and the run animation once again i'm going to leave the mouse alone so now you see this is the idle animation let me go down a little bit idle idle and then run okay so that's what our any major is doing for us so first running the idle animation then running the zombie run animation now what you can do is if you want to see this a little better well you can zoom in that's one thing you can go to your zombie animator and actually to really make sure click on the zombie animator controller here click on to it and run the game and you will see how the idle animation is running and once the idle animation is done you see the zombie run animation starts so that's how you can see at which state your game currently is so i'm going to drag the animator back here so i can see it in a better format so it's a little bigger you can use a middle mouse button in order to move around easily inside of your animator now let's look at parameters and we have done that before in our 2d game in our space invader game because we can click on this transition and we can see that we have certain conditions here so we can say what the condition is for this to run as we currently have no condition after the idle animation is done it automatically jumps over to the run animation so let's go ahead and add parameters here so here the top left hand side you can move between layers and parameters and i'm going to go over to parameters i'm going to create a new boolean here and i'm going to call this one is running like so and maybe i should call it is running with the lower eye like so it's running and now what i can do is i can click on this transition and i can select conditions so here click a plus button and you will see is running will be selected as we have no other options here is running is going to be the only one and i'm going to set that to true so once is running is set to true so this tick box is checked then the transition will move from the idle to zombie run so let's deactivate it by default let's go over and make sure that our animator is on the side next to our game and then let's move over a little bit so that we can see it a little better okay so now we have our idle here let's start the game it will go over to idle but it will not start the run animation even though idle is done okay idle is done and then it's going to do idle once again let me click on the running let me move over here let me is running click on to that and you will see once the idle animation is done it will start running okay so now this condition is met so this condition that we had set up here is now met and that's why our transition can be executed so here our make transition transition that goes from idle to zombie run you may also have noticed that it takes quite a while for the idle animation to stop and is running to be executed so let's run this once again without having this has exit time activated because you see here there's an extra time which is pretty long three seconds until there's the transition from the idle state to the running state okay so let's deactivate this has exit time let's run it once again now let's see our character or our zombie is in the idle state all right and now let me click on is running you see it starts running straight away so this time it doesn't wait for the idle animation to be fully done because it has a certain exit time it means it needs to finish the idle animation before going over to the zombie run animation i created an extra video on that in our space invader example where i looked where explained that has exit time in more depth in the next video we're going to add a couple more transitions in order to also go back to the idle animation after the character has run quick pause the video that you're watching right now is just a fraction of the entire fps course and of course you're not only learning how to build a first person shooter but also make it a multiplayer game so you're going to learn a bunch more things than in this youtube video it's a seven and a half hour course and you can not only get the course but you can currently also get the book with a 50 discount definitely check out the link in the description below to improve upon what you're building in this video and become a real multiplayer game developer we are going to take care of the transition back from running into idle okay so let's go ahead and click on zombie run and therefore we can also make sure that our animator is going to be full screen here so i want to move from zombie run to idle therefore i need to click on zombie run make a transition and you see this transition pops up which also can snap towards where it fits so for example into the idle state so let's click on this transition what i want to make sure of is that my transition from zombie run to idle is going to be connected to a condition so only if it's running is set to false i want to make sure that the idle animation will be running okay so we're going from zombie run to idle if the condition of is running is set to false and the other way around we make sure if the idle animation is running and then the is running boolean here is set to true that it jumps over to the zombie run animation so what i'm going to do also is i'm going to get rid of this has exit time because i wanted to transition very quickly from running to the idle animation and the other way around even though this might look a little off in some animations or it could look a little off in some animations it shouldn't be too much of a problem in our particular game but if you want to be super precise you definitely need to take the has exit time into consideration for some of the animations that you're going to use so now let's test this and let's run our game here there we are let's move over to is running so i'm going to click on this is running here and we are going to see that our animation well our running animation went through it's a little difficult because my mouse is being connected to the game as well so here let me deactivate it you can see it goes back to the idle animation and runs through it again and again i go to running it runs through the running animation and back to the idle animation okay depending on whether i activate it or not you see really goes very quickly so the animation is very clean alright so that's it for this video in the next video we're going to start looking at the enemy controller so the enemy manager which will take care of the ai so see you there all right so now that we have a general idea of animations and animators let's make sure that our enemy can actually run after us and we're going to do that within a couple of videos so the first thing that i want to make sure is that my zombie has a script that will take care of the zombie following the player okay so let's go over to our assets here let's create a new script and i'm going to call this one enemy manager so here enemy manager so it's going to manage our enemy so let's check this script out the only thing that i'm going to do for now is going to make sure that our enemy manager finds the player so let's go ahead and find the player based on his tank and this is actually something that i would like you to try to do yourself so in the start method please assign the player game object using the method that will find the player based on his tag on the player tank so to speak okay i hope you tried it and it's going to be basically this here where we assign the player game object based on find game object with tag and then it will find the player with the player tag so let's save this script and let's get back to unity and let's actually make sure that our first person player here has this tag assigned to him so you see here the first person player has this tag player and our zombie if we look at it needs this script now so let's add the script to the zombie this enemy manager in here let's also make sure that we are applying all changes to the zombie everything that we changed with our zombie here let's save the scene while we're at it and now you see that the player is an empty game object before we start the game but now let's start the game and see if that's going to change and we can see it changed to first person player which is exactly our player so it's great so it's working so it finds our player based on this one line of code that we added so this find game object with tag here okay so now we can use that for the zombie to run after us but before we can do that we need to make sure that it actually knows where to run so we need to give it a certain well in instruction so it needs to know what the ground is and where it cannot run towards so that it cannot run against the wall for example and those kind of things therefore we need to look at the nav mesh as well as the nav agent which is what we're going to do in the next video so see you there welcome back in this video we're going to look at what nav mesh and the nav agent are before we're going to actually implement it in our game so the nav mesh or navigation mesh that's the different name for it so the the process of creating a nav mesh from the level geometry is called nav mesh baking so the process collects the renderer meshes and terrains of all game objects which are marked as static and then processes them to create a navigation mesh that approximates the walkable surface of the level so you can see that this is the nav badge so everything that is blue here is walkable so to speak so you can see the enemy cannot walk into posts it cannot walk into trees it cannot walk on top of for example houses or into houses so it can only walk on this blue surface and it could walk on top of houses as you see here as well because they're great flat surfaces but it cannot walk on certain other areas of the map so once you have a nav mesh baked for your level it's time to create a character which can navigate the scene and this is done using a nav mash agent component there's this new component that we're going to assign to our enemy and then the enemy will know where it can walk on and this lets unity know that the game objects similar to the character controller can navigate through our scene and gives us useful methods to use so let's use them to make our zombie move and follow us in the next video welcome back in this video we are going to use the nav mesh in order to prepare our world so our map so to speak for our zombie to be able to walk in it and therefore we are going to use the nav mesh that we can find under window ai navigation so here you will find this new tab which is called navigation here and it has this big option so this tape tab that is called bake now here you can change up a couple of settings for your agent so your baked agent size for example so what you can see here is that on one hand the agent has a certain radius so how thick is the agent for example if the agent is super wide then it cannot walk past certain areas of the map because it's too narrow there for example then the same goes for the height if there is an object blocking at a certain height and the agent is taller than that then the agent cannot pass this area then we have the max slope which means the angle which our enemy can walk for example so if the slope is too high then the enemy cannot walk past this area if it's super low then he can still walk past it and here we can define what the maximum slope is that our agent can still walk so if you have a map with hills and stuff like that then you could define here which areas the enemy can still walk so which kind of height he can still progress in terms of angle and what he cannot walk past then you can define the step height so how high are the steps that the enemy can make so the agent can make so let's say 0.4 meters in this case is how high an enemy can still walk so for example here you can see that there is a certain height that our pedestrian walk here has so if the step height was zero for example then our enemy could not walk onto this pedestrian height so that's something you need to take into consideration when it comes to the step height so we're going to pretty much leave everything as it is you can see you can even define the jump distance so if the enemy can jump for example or how high he can drop how much he will be well able to drop before the mesh will not consider it as a walkable option and so forth so i would say let's just leave it as a default and here you will find the bake button okay so we can bake our nav now our nav mesh but before we do that let's actually make a couple of changes to what we want to even be part of our nav mesh so what i'm going to do is i'm going to make sure that my invisible walls and woods are deactivated so here let's uncheck them okay and then i make sure that everything else so my streets my blocks my buildings and decoration are set to static here okay so here you need to make sure that all of them are static you can change the children so i'm going to deactivate it so that they are in fact going to be static because the nav mesh can only make static game objects so things that will not change they will not move they will not be influenced by gravity or by physics or anything like that they will be static okay so we make sure that all of these fields are static but invincible walls and woods are not okay so if we look at it we can also make them unstatic here okay so now why are am i deactivating the invincible walls and woods well that's because i want my enemy to spawn here so i want my enemy to spawn let's say somewhere where we cannot reach as a player that's why we have these invisible walls because we shouldn't a be able to walk past this field or this area to for example leave the game and that's why we also have these woods so that they block division but our enemies they should in fact be spawning just behind those trees for example or behind this wall here because we cannot see where they are coming from and this makes the game feeling a little better okay so it would be weird if they just spawn out of the blue somewhere you can see where they come from so you can use this little trick but you just spawn them somewhere where you cannot go and what you cannot see through and then they come from this area so from this behind the trees area here for example or behind those trees or behind well these trees here and so forth so we can later on make sure that we have spawn points that are somewhere where the player cannot see and but a player cannot get to okay so let's make sure we deactivate those two again so the invincible walls as well as the woods and now we can actually bake our city okay so now we can go over to our navigation here and bake it so let's click on the city or actually we can just click on the elements that should be part of the nav mesh and then bake them once you click the bake button depending on your hardware it could take a little longer but overall this is what we're getting so all of this blue area is where our enemies can now walk through so you see they have a certain width which is why there is an area here around this post which is still being considered that the enemy cannot walk past it or next to it but that's overall now going to be the area where our enemy can walk then we can even get up here well potentially if this is 0.4 height so the steps height is at 0.4 okay so now we have the areas where our enemy can walk and you can play around with those fields here as i said so for example if we change the step height you can see now it can get to certain other areas that it couldn't get to before i'm going to use 0 4 here to bake it and make sure that that's going to be the default setting for our agent in our case it will be the zombie that will use that so now we have an f mesh that is active we have used a nav agent for its size and all of those settings we can deactivate the display here show nav mesh we can deactivate it anytime but if we go to the inspector it will be deactivated either way so now let's make sure that we activate our invisible wall and well walls and the woods again and now we should be good to go for the next step where we're going to make sure that our enemy can follow us so see you there welcome back in this video we are going to make our zombie actually follow us and we can do that by giving him a nav mesh agent here so let's add a component to our zombie click on the zombie go to the add component button and select the nav mesh agent from there you can just search for it and then add it so the agent type will be like a humanoid and you can see it has a certain speed an angular speed so how quickly can it turn an acceleration so how quickly can it accelerate and so forth the interesting thing here is obstacle avoidance are the things that we have seen with our nav mesh agent before which was that it had a certain radius a certain height so it's pretty much the same thing that we can see here so it will auto repath it will auto traverse off of me so it has some pathfinding in it as well so now we can overwrite our changes that we made to our zombie prefab and we can now go over to our script in order to make sure that this nav mesh agent actually does something because currently it won't do anything we need to make sure that we add the ai namespace here so unity engine dot ai and then once we have that we can go ahead and get the component called nav mesh agent so nav mesh agent and then it has this property called destination so the destination if you hover over it it will say gets our attempts to set the destination of the agent in world space unit so what should be this the destination of our enemy well i would say it's the player that's why we created the player here right so how can we get the position of the player game object i hope you tried it yourself and you paused the video so we're just going to go and go ahead and use the transform.position here for of the player so player that transform that position so this will give our nav mesh agent a position which it needs it needs a 3d vector and position is a 3d vector so now our enemy will update every single frame or we'll try to walk towards the player every single frame so even if we are changing our position it will constantly update the position okay so let's go ahead and see if this is actually going to work let's see if our enemy our zombie is going to follow us and there we are it tries to follow me so you see it's walking it has a certain speed of course the animation is a little off still let me walk past it you see it has a certain speed at which it can rotate okay so this is the angular speed that we have set up at 120 and if we were to change that it would be a little faster at changing but you see the zombie is running after us we cannot shoot it yet because we haven't implemented shooting but at least the zombie is running behind us and let's say let's go on to the truck here for example let's see if we can get us there so you see he cannot get us here that's why he stopped running after us so once i'm at the ground again you see it runs after me if i'm in the air well it can still reach me but as soon as i'm up here it cannot reach me anymore which is now a blind spot in our game so now we could make it so that the zombie can still reach us by either giving him huge relax or just the capability to jump or climb or whatever or we could add a little bit of a slope here or like a little path that the zombie can still walk in order to get up here but then we would have to rema bake our nav mesh okay but that's it for this video so now you see how you can make sure that your enemy is following you and then the next video we're going to see how to add animations to our anime so that it follows us so see you there welcome back let's make sure that our enemy is now going to also animate the either running animation or the idle animation okay so we have the zombie run and this idle animation in our animator and we saw that we can just trigger this is running boolean for one of the two things to happen so either to go to the idle if it's not running and to go to run animation if is running is true so in order to modify this based on certain behavior we can get the speed of our enemy from the nav mesh agent so we can just check if the velocity of our nav mesh agent has reached a certain point and if it is bigger than a certain value we can just go ahead and set the boolean to is running true so let's check out how this actually works so we can check here if the get nav mesh or get component f mesh agent dot velocity so here access the current velocity of the net mesh agent component which will basically just give us the speed here right dot magnitude so this returns the length of the vector which shows us how fast the enemy is and if that is greater than one we can just go ahead and say okay this guy is running so let's start the running animation so this value is just one value saying okay well if the speed reached a certain value let's start running you could also use a different value here would be fine as well but one i think is fine because the magnitude is going to be a float okay so you could use a float here as well which is fine so now let's go ahead and create the animator object so that we can then access it okay so here public animator i'm going to call this one enemy animator like so and now we just need to make sure that we set the enemy animator and our update method here to be set bool and here we can now set is running to be true okay so now we're setting this boolean here this is running boolean we're setting it to true if the enemy is at a certain speed but if it's not then we want to make sure that it's being set back to false okay so here if the speed doesn't reach a certain magnitude then let's use false here because then we know that the enemy should be using his idle animation and not be running okay so now let's get back to our game alright and now let's see that in action so therefore our enemy will need an enemy animator okay so let's give it an animator and that is going to be the animator that we have inside of our root okay so you can just drag the root here into the enemy animator and root will have an animator so here root has this animator and it will know to use this animator here okay so now let's run our game let's see if the animation is going to be executed you can see that the run animation starts running and once we are close by it's at the idle animation once again well it's actually not let me see stops running then he's idle because he's not moving right we cannot see it very well only if we go to the scene view here you can see the idle animation once i go far away he starts running again so now we have two problems one of them is that i'm not super happy with the speed of the math mesh agent so in my opinion something around 5.5 looked quite good because it fits roughly with the animation of the enemy but now i also want to make sure that the running animation is going to maintain while his running is true all right and in order to fix the fact that our zombie running is not looped you can activate so go over to your animations on the characters assets in tutorials you assets and the zombie run here make sure that the loop time and loop pose are set to true and now let's check it out once again and you see now our zombie is going to run after us and i think it looks quite good in terms of how fast he's running and the animation fits quite well in my opinion you can of course play around with this value just to see what looks better you can really tell that this guy really wants us huh so he looks quite scary he wants us but we cannot shoot him well he can't hurt us either so it's off all right we're going to implement the hurting functionality as well as the shooting functionality a little later but for now let's have a quick break let's make sure that we save our scene and see you in the next video all right in this video we are going to add a functionality that will allow us to notice whether we collide with the zombie or the zombie collider with the character because currently the zombie just runs into us and nothing happens right we don't have a debug log nothing so let's make sure that we are debugging once the zombie hits us therefore i'm gonna go over to the zombie and i'm going to give the zombie a capsule collider here like so and i'm going to put this capsule collider a little higher so here you can see this is the capsule collider here i'm going to set it up a little higher so the y coordinate will be centered at two the radius should be something around let's say one okay and the height will be 2.5 so something around that would be fine we could use different values here which would be fine either way so two would probably be too much one is i think it's it's fine all right so if the zombie is at this point close to enough to our player then we want something to be triggered we will also need a rigid body for this so let's make sure that we add a rigid body to our zombie and i'm going to make sure that i constrain everything okay and i'm going to deactivate gravity as well here because i don't need to well i don't want any of this to impact our game our enemy so the rigid body should not be really impacted but we're going to need it for what we're going to do next so let's make sure that we open up the enemy manager but before we do that let me actually make sure that i apply all changes now in the enemy manager we can get the on collision enter method or use the on collision enter method this one here and we've used it many times before so i assume that you know what it does and here we're just going to check if the collision was with the player so if collision game object is going to be the player so if they are the same so to speak we know that the enemy has hit the player so debug log and here we can say something like player hit so let's check this out let's get back to our game and let's also by the way once we made the changes let's make sure that we save our scene and let's run the game go over to the console as well and now you will see player hit okay so let me run away and boom player hit okay we're even being pushed up a little bit i know there might be two questions that you have so one thing is that we're getting pushed away at this point so we're getting pushed away by the zombie which is a thing so you're getting pushed up a little bit you see here so which is something that you can avoid by changing the size of the colliders of your enemy as well as of you we're going to take care of that a little later but then another thing that you might wonder is why we are even using a rigid body even though we're deactivating gravity and freezing all positions and all of that kind of stuff well the thing is we need that in order for us to be able to use this on collision enter method which says it's called when the collider slash rigid body has begun touching another rigid body collider so while we're not actively using the rigid body as such but we still need it for this on collision enter okay so that's it for this video in the next one we're going to see how we can lose health when we are hit by the zombie enemy so see you there welcome back in this video we are going to take care of player health so we want to reduce the player health once the zombie hits the player okay so the enemy knows how to hit the player but we don't have a script for the player yet so let's go ahead and create a new script i'm going to call this one player manager and this one for now it will have a very simple task it will take care of health okay nothing too complicated so we can create this public float health which we can modify and we are going to set that for example to 100 and then we will need a method that will be called once the player is hit so let's create a method public void hit and i don't mean the controller something hit but our own method and here i'm going just going to say we can get a float amount of damage okay so this will be the parameter that we're getting and then we're just going to say reduce health by the amount of damage that you have that's it so this will basically say health minus damage will be the health so we are reassigning health to whatever damage was subtracted so let's say we're at 100 health and damage was 20 and we are hit so this method is called once then the health will be t so now in order to trigger this we need to go back to our anime manager so let's save this script the player manager script and here instead of just debugging a log player hit we need to apply a certain damage so let's first of all make this a variable that we can very easily adjust from unity itself by creating this damage value here of let's say 20f because this will be a float again right and then we can go ahead and now inside of this enemyhit thingy so where we had this debug statement we can just go ahead and call the method from the player manager component that was called hit and we need to pass the damage to it so this way we can now from the enemy manager call this player manager method called hit because it is public we can access it so we can just get the component player manager which is the script and we call it hit method at this point we can save our script and let's see if we can actually reduce the amount of health the player has once we're getting hit by the zombie so you can see here now in our player movement well we need to assign this player manager script to the player as well so let's add that to the first person player and now let's go ahead and be attacked by the zombie okay so the zombie was super fast you see it's attacked us bomb eddie health and it detects us once again 40 health 20 health and well now we're on top of him so you can't hurt us we go next to it bomb now we're at zero health so well of course what we want to achieve is that the game restarts at least for now once we are at zero health so the player died and we need to replay so let's create this first loop this complete game loop by reloading the scene on zero health in the next video all right now that our player can lose health it's time to also reset the game and how i'm going to implement it is going to be rather simple and that is once the player health is at zero over below that we are just going to reset the game so in our player manager we have hit where we reduce the health right so here we can just check if the health is below equal zero so if health below equals zero then reload the game so how can we reload the game well first of all we will need to have the scene manager here so see management then we can use the scene manager class here and just load a scene and i'm going to load the scene with index 0. so build index zero that will pretty much be it so let's save this script let's go back to unity and also make sure that this scene that we have here so the game scene is actually part of our build so over here in build settings in my case you see there is no scene well there's one that is deleted but i'm just going to add open scenes in there and now you can see we have the scene slash game scene which has the index zero so that's the build index that we're going to use here in our player manager script so this one here and it will load our scene so let's see if we can get killed by the zombie here so there we are he pushes me away and my health let me see and there we are so now it reset the game and we also have this graphical bug where the lighting isn't correct but that's a unity problem once you actually build the game you won't have this problem alright so the reset actually works now let's fix this problem with the zombie pushing us up a little so there are certain values that we can use that will help us with that and that is if we change the capsule collider of our zombie here to the center being at 3.3 so it's at the head's height so to speak then the radius being a little smaller something like 0.6 and the height being one so it's basically just going to be the head that can destroy us so only the head can eat us and hurt us so to speak okay so let's test this again and see if the enemy will still push us up if he reaches us and you can see now the zombie reached us and he does not push us up anymore which is good all right so that's it for this video see you in the next one welcome back in this video we are going to use raycasts in order to shoot because what we want to do is we want to shoot from the camera position because the first person player has the camera inside of the first person character here the main camera and what we want to do is we just want to shoot this blue line or towards this blue line here okay so this is the front of the camera if we look at it from the top it's a little easier to see so we're shooting straight forward that's how we are going to aim now you could of course say the weapon is slightly to the right you could change the camera position a slight bit for that but i think it's going to be precise enough for our case so we're going to shoot straight this blue line wherever the camera is facing towards that's where we're going to shoot towards okay so let's go ahead and create a script that will take care of the shooting functionality and i'm going to call this one weapon manager now let's check out this weapon manager here and inside of the update method i'm just going to check if the left mouse button was clicked and in order to do that i can use input get button down and the button down that we're looking for is called fire one okay so if you look at the axis in your project settings here input manager there is this fire one which is your left mouse button so it's either left control that's also what you can press or it's the mouse zero button okay so this will shoot the name is fire one with a capital f and the one fire one so if we press the left mouse button what do we want to do well that's where we are going to shoot so let's for now just use the debug log to test if this works so let's say shoot let's save the script let's get back now at this point let's make sure we assign this to the weapon so this weapon manager script because we have the upper chest the right shoulder the right arm is it here yes the right hand owns the weapon so it's pretty far down the hierarchy here but that's where our weapon will be so let's assign our weapon manager to the weapon so here let's add the web manager and also the first person player let's up apply the changes by the way just to make sure that the weapon manager will be part of our first peterson player prefab alright so now let's run the game and see if pressing the mouse key will do something and i will pres and i will press a couple of times now let me go over to the console and you see every time i'm pressing all right so that seems to work so now instead of just debug logging here let's actually do something useful and let's shoot array so we have used race before and i'm going to create an extra method for shooting here void shoot so i'm going to call this one and it will need the raycast hit here so raycast hit is a struct which is a structure used to get information back from a raycast perfect that's exactly what we want so i'm going to call it hit okay just raycast hit here and we can now use this in order to store what we have hit with it and therefore we can use physics dot raycast and this will now cast array so cast array from point origin in direction direction of length max distance against all colliders in the scene returns true if the ray intersects with a collider otherwise false so if we hit something it will return whatever we hit okay so there are multiple different overloads here you can see plus 15 overload so in total 16 overloads so let's just start with the first one so first of all we need to say where the origin is okay so i'm going to use the origin vector 3 here so i need to say where the start putting point of my shot should be therefore what i'm going to do is i'm going to create a new game object here which i'm going to call playercam which will be their player camera now if you wanted to be super duper precise you could say okay it's the weapons central point where the bullet comes from okay so that's up to you i'm going to save the script now and the code is complaining here so let me quickly un comment this out for now so what i want to do is i want to use my main camera as i stated because the camera will always look towards where we are looking towards and it will shoot from there so that's why we're going to use the camera position here as i stated earlier so it will shoot from here which is slightly below the actual weapon spot okay it's super close but it's not exactly there it's totally fine still all right so now what we can do is we can use the player cam here in the weapon manager script so let's make sure that we drag the camera in there and it's this main camera so you can just go ahead and search for main camera inside of the scene this one here and you can assign it there or alternatively you could have dragged it in there that's fine as well so now we are going to use this player camera in our script to be the starting point so the origin of our raycast so here let's use the playercam position and therefore we need to get the transform property and then the position property so this will be the origin where we cast away from and by the way now you can see an overload that is closer to what i wanted so you see we have an origin then we need a direction and then max distance or a max distance so let's use the direction which will just be forward i just want to shoot forward so therefore we can just use transform dot forward then i can define the max distance for now let's leave it out and i also can get here the out raycast hit okay so you see here we had to have this hit and i would like to know what i have hit okay so here i can just say out hit what that will do is it will say whatever we hit will be stored inside of this hit variable so that's what this out does for us but then we can add a semi colon here that would be fine for now but then there are multiple other details that we can pass so let's look at them we can add the layer mask we can add the max distance for example which is actually what i want to do here as well so i'm just going to say that we can define the range up here public i think it's a float let me see what it says here let's look at the overload you can always check here so layer mask layer mask float yeah the max distance is a float so that's good so let's use this as range and now we can define the range to let's say 100 okay so this will be the default range that's how far we can shoot with our weapon and then we can use this range here so now this raycast will use this overload where we have the origin the direction to where it will shoot it will shoot forward the origin will be the camera the raycast hit will be our hit variable that we have here and then we have the max distance that we set up as range now let's go ahead and check if this worked because you see this raycast method returns a boolean so what we can do is we can surround this with an if statement here like so and then we can just say what we want to do if it hits something because it will return true if it hits something and falls if it doesn't hit anything within the range in the direction or towards the direction of forward so let's use debug log hit here this time so we're going to say we hit something all right and now that we have that we must of course run our shoot method in here so let's make sure we execute our shoot method in the update method once we press the shoot button so the left mouse button so to speak so let's save the script let's get back to unity let's save the scene as well while we're at it and once it's loaded let's run the game and see if we can shoot something so let's shoot the air first you see we don't hit anything now let's shoot the zombie and you see every time i shoot something even if i shoot this ball here you will see it will say hit so now we of course will need to know what we have hit now we can try to shoot the zombie but that won't help us much because well the zombie is invincible at this point the only thing that can kill the zombie is the fact that we can pause the game anytime all right so that's it for this video now we don't know how to use the raycast hit in the next video we are going to add a crosshair to our screen so that we know where we are shooting welcome back in this video we are going to take care of the knob and well basically the cross here because if we play the game we don't know where we are shooting so we can have an estimate where we are shooting but we never are sure or can be sure so let's change that let's add a little ui element will make it a lot easier for us therefore let's go ahead and create a new ui element called image or i'm just going to call this one cross hair so this will be an image that we're using here and what i want to make sure is that it is centered here okay i'm going to use a width of 10 and the height of 10 for this and the source image that i want to use is going to be the knob okay so you see we have a knob inside of the asset so if you downloaded the assets from us you will find this resource image there and now we will have this knob in the center of our screen you can see it there if you want to make it a little bigger you could change that from 10 to let's say 20 for example that would be fine either way so now you just have to define how big you want this knob to be but now this knob is going to be pretty much in the center of our screen and it displays where we are shooting so that really helps you will have to make sure however that your crosshair is centered so the anchor presets are center and middle so here this one in the middle the position is 0 0 which will be just in the middle of your screen and the width is whatever you want to set it and then of course the source image should be your knob or if you have an actual cross you could also use a cross there however you prefer and now i'd say let's take care of the actual health system of the enemy so see you in the next video welcome back in this video we're going to take care of the health system of the zombies and we're going to take care of shooting the zombies so that they can actually die and disappear once their health is at zero or lower and that is something that you could implement yourself actually because you should be you should be capable enough to implement that by this point so you can learn a lot from of course our health manager of the player so this player manager here you will need to use the weapon manager and the enemy manager to get this done so i wish you all the best if you want to try it for yourself i hope you will try it actually all right so i hope you tried it as i said and now let's go ahead and take care of it so inside of the enemy manager we have the damage that the enemy can make so the zombie can generate once biting us so to speak but we can also now add a health for the zombie as well so for the enemy so let's use 100 here for example and then we can go ahead and actually reduce this health using a hit method so we can use the same kind of method that we used well not the same method but we're going to build it the same way so we're just going to use public void hit here public because we want to make sure that we can actually use it from other classes or from other script and i want to pass how much damage a shot can do because this will allow me to later on have different weapons that do different types of damage so here hit float damage and now what should happen here is the health should deteriorate based on the damage that we are getting so this method now of course needs to be called from our weapon manager script because here that's where we are shooting and currently we're just debug logging here so we're not doing anything useful as of now so instead of just doing this debug log here let's actually check if the thing that we hit has an enemy manager assigned to it because if it does then we know that we hit an enemy so here enemy manager i'm gonna call it enemy manager like so we'll get hit transform get component and the component that we're getting is the enemy manager okay as we have done before right so if the enemy was nearby with us here we got the component of the player and we then checked if the collision was with the player then we did the hit damage now this time it's very similar we're getting the component and we're checking if enemy manager is not null so only if it's not null we want to do something with it because then we know that we hit an enemy so let's use the enemy manager to call its method hit and let's give it some damage now of course we need to define how much damage our shots will do so public float damage let's say our damage is 25 so now every shot will do 25 damage and now we can just go ahead and say hit with damage now this will allow us to hit the enemy but it will not kill the enemy so let's test this real quick all right so let's shoot the enemy a couple of times should shoot choo choo choo choo choo and now let's actually check the scene and click on the zombie to see its health it has 75 health okay so it seems like i didn't shoot it enough yet so let me click on the zombie and let's see if i can kill it okay now its health is at zero and well actually my health was it so either way i killed the zombie but it didn't die that's what i wanted to say so you see i'm really bad at these games so let's go ahead and actually take care of killing the enemy and that's what we can do in the enemy manager because once we hit the enemy we can check if the health of the enemy is below zero so here if health is less than equal zero we know that we need to destroy this game object now either you can use this here or game object either way should be fine this will destroy the enemy manager holding game object which means the zombie because the zombie holds this enemy manager and this will destroy the zombie so here destroy enemy zombie okay now let's check it out let's see if i can actually kill the zombie and i feel like by the way let me look at the zombie here i feel like the zombie isn't big enough i need to make the zombie bigger maybe so hit this part here let me make sure that this part here this mesh agent is a little taller 3.5 maybe or even 3.9 something like this okay now it will be a little bigger alright so let's play the game let's see if i can kill the zombie before it kills me okay yeah i got him got him okay i needed quite some shots even headshots didn't help but yeah i killed the enemy so the zombie was gone the zombie was destroyed which is great so now we know how we can actually destroy enemies and i'd say in the next video we're going to implement the animation because currently we are shooting and we don't really see anything so of course we need to have a little animation of the actual shot then maybe even a visual representation like um i don't know like a fire splash or something like that as well as what we're going to do is we're going to move the weapon just a little bit so create a little recoil effect which will give us the feeling or the sense of shooting quick pause the video that you're watching right now is just a fraction of the entire fps course and of course you're not only learning how to build a first person shooter but also make it a multiplayer game so you're going to learn a bunch more things than in this youtube video it's a seven and a half hour course and you can not only get the course but you can currently also get the book with a 50 discount definitely check out the link in the description below to improve up on what you're building in this video and become a real multiplayer game developer so let's take care of that therefore i'm gonna go over to my animations here instead of characters so characters animations let's create a new animator controller this one here animator controller let's call it fps animator like so let's open it up and now let's drag in fps idle as well as firing okay so these will be the two animations as you see we have prepared those two for you already and what we will need is a new parameter here a boolean i'm going to call this one is shooting okay this boolean here and now what we can do is we can make a transition from idle to firing and this transition should only run if his shooting is true and now from finding firing to idle and this transition should happen if his shooting is set to false okay so these are going to be the two animations that we have here now we also want to make sure that they don't have an exit time okay so let's do that for both of them and also here if you open up the settings i would like to deactivate this fix to duration for both of them okay what that will do is it will make sure that we can shoot and shoot again like halfway so the animation will stop halfway and restart the the moving forward so to speak if we are shooting straight while the recoil is still running so it will not go all the way back before the recoil will start once again it will basically restart halfway so to speak and that's exactly what i want in terms of this behavior in that particular case so now we need to toggle this is shooting for now let's make sure that we test it like so here so we have the two screens let's see actually we need to assign the script first so here the animator of our fps character let's add this fps animator to him like so so make sure click on the fps character you see the fps character has an animator that didn't have a controller as of now but now it does have one so let's run it and let's see if we can shoot you see fps idle is being executed all the time so now let me shoot by triggering this shooting and you can see this is the effect that i was talking about okay so activating deactivating and if i do it very quickly you can see now we have this recoil effect of my weapon all right so that's it for this video now we have added the recalling effect at least the theory behind it now let's make sure that this will be triggered once we are shooting so see you in the next video welcome back now let's actually animate once we are shooting and make sure that we are setting the bullion correctly so we have this boolean is shooting we can activate it and deactivate it so we want to activate it once we are shooting but just the frame later we want to make sure that we're not shooting anymore so at least this boolean is deactivated so let's have a look at how this is going to pan out so the first thing that we will need to do is we need to go to our weapon manager and that will be under our scripts here weapon manager this one here so this is where we are shooting right so what we can now do is in the update method we get the button down fire so we know we shot okay so now what we need to do here is we need to start the animation so let's create a variable animator that will be the player animator even though it's not really an animation for the player it's actually an animation for the weapon but it's more or less the same thing here right so we get the player animator here and we will need to assign it of course to our weapon manager script in unity so now what we can check in the update method not only if we get the button down but also if we are shooting so we can just say player animator get bool so we can check is the bool is shooting set to true and if that's the case then go ahead and set that boolean to false again so here is shooting let's set that to false like so and then at this point do the actual shooting we once we get the input detected now inside of shoot itself we also need to make sure that we are actually setting the shooting to true at one point because otherwise we'll never be set to shoot so player any major set bool and here we're going to say is shooting should be set to true so let's look at this by frame by frame steps so here at the beginning the shooting is set to false then input is detected and the shoot method is called and then at the bottom you see in the shoot method the boolean is shooting is set to true that's in the first frame well in the moment that we're shooting then in the following frame the shooting is now true so we're setting it back to false then input is detected and we're shooting again or we're setting the shoot method again and the shoot method will set our is shooting to true again okay so that's what is happening in our case right now even though this might not be frame one and frame two in the sense of exactly after another because we don't shoot 60 times per second for example if we have 60 frames i don't think that you can shoot as quickly some people might be able to do that but most of us can't so that is how it's going to work okay so now let's make sure that we are saving the script by the way and once we have saved the script we can go back and we can now make sure that our weapon manager and our fps character slash weapon here owns the weapon manager it now needs a player animator and the player animator is going to be the fps character or at least the fps character owns it because here that's where the animator comes from right so this animator that is owned by the fps character holds the controller that is our fps animator controller which then holds the animations and the order in which they are being executed so it will now set this is shooting to true and false based on our behavior so based on whether we shoot or not so let's see if this is actually going to work now so let's shoot and you see the animation works so even if i'm very fast here you see it doesn't finish the animation entirely and it works well here so let's try to shoot this little bastard and there we are dead zombie dead okay cool so that's it for this video see you in the next one so let's look at spawners and how spawning works so similar to titles like call of duty and gears of war wave based spawner systems are in short a mechanism to spawn enemies in waves based on separate rounds usually upping the difficulty with each round so in our case we want enemies to spawn from set spawn points with an amount depending on the current round we are in then using their pathfinding system to find their way to the player so they should all run towards us this gives us the possibility to modify each round how it feels what enemies will fight and there's that even things like movement speed special abilities and a long list of other features that you want to have so let's get implementing therefore let's go back to unity and we mustn't forget one thing and that is our navigation here okay so you might recall we had these blue areas where our enemies can run on they cannot run on areas that aren't blue okay so that's something we need to take into consideration so we even made sure to leave space for enemies to spawn outside the map boundaries just so we don't see them appear out of nowhere so if you look at the map here you can see that here for example is an area where the enemies could spawn from and in front of it we have a invisible wall so here you cannot really see it very well but yeah there is an invisible wall so we cannot walk through it but zombies can now come from for example this spot here and then walk over here we cannot see them when they are spawning which is always good so that's something you should try to achieve so let's go ahead and create some spawners therefore i'm going to go ahead and create a new empty game object which i'm going to call spawners now let me make sure that in the inspector the spawners are reset so it's set to zero zero zero it's always good if your parent objects are repositioned at 0 0 0 and now let's create individual spawners so now let's create an empty game object in here i'm going to call this one spawner we can even go as far as to say spawner and then zero in brackets so this will be our first spawner and then we will duplicate this one to create more spawners i'm going to duplicate this a couple of times using the control and d key shortcut and then the positions that i would recommend that you use are for spawner 0 15.75 for the x position 0 for the y position and minus 13.3 and by the way actually you can just copy them from here so just pause the video and set up your spawners with these values if you want to use the same spawner positions as we have used okay so here these are the ones that i'm going to assign now what you also want to do is or i would recommend you do is you add a little gizmo here so i'm just going to add this little diamond gizmo currently they're all at 0 0 0 for me but this one spawner here is going to be over here so i want to be able to see it in my scene and it seems like the gizmo is a little small so you can also use this one here to make it a little more visible so this will be spawner zero and then we have the individual spawners here one two three four and so forth once you're done with the positions that i shared with you just a bit ago you should have spawners at these locations as you see here so these are the five locations they're just behind trees and behind these walls that we cannot penetrate as the player and that's where we want them to spawn this in the middle here is going to be the player and not the spawners right so these slightly transparent squares here that's where the spawn should be all right with that i'd say let's implement the spawner code that it will actually spawn those monsters for us so see you in the next video welcome back in this video we are going to take care of spawning enemies and therefore i'm going to create a new script i'm going to call the script game manager because well it's going to be the game manager that is going to take care of spawning because the game manager should also take care of which round we're at and how many enemies we have currently and stuff like that so you see here game manager you get this tool wheel as we have seen before whenever we created the game manager so let's go ahead and create a game manager object here as well straight away and let's drag this well let's first of all reset this position and let's drag the game manager in there okay so now we will have a game manager in our game that's always good and now we can go ahead and take care of the script so the first thing that i would like to know is how many enemies do i have in my game that are live and then which round am i at so i'm going to create these two integers that we can then adjust and also see in unity straight away of course you could have also made it serializable here for it's to be available and made it private but i think this will be fine so now inside of the update method what i'm going to check is if we have enemies that are alive or not and if we don't have any enemies alive which means we are at zero we're going to increase the round so at the beginning we're at round zero at the beginning we're at zero enemies that are alive so that means in the first iteration of this update method this will be executed and the round will be increased so what do we want to do once we increase the round well we want to call the next wave so let's create a method that will take care of calling the next wave and i'm going to call this method next wave and we will need to pass the round to it so public void next wave with the route now of course we want to spawn the enemies at random locations so let's go ahead and make sure that we get the spawn points in our game manager script so this will be an array of game objects i'm going to call this one spawn points so now what i want to do is inside of my next wave i want to randomly spawn an enemy well an enemy at a random location out of those spawn points that we have and we've seen how to do that before so i'm just going to paste the code in here where i'm getting the spawn points length and and i take one of the spawn points randomly between zero and the length of the spawn points using random.range so this will now be the spawn point at which i want to generate a new enemy so what kind of enemy do i want to create well it's always the same right we need to know which game object we want to use and i'm going to use the enemy prefab because that's the point where i want to generate the enemy now that we have the location and we have the enemy that we want to spawn let's go ahead and actually spawn the enemy and therefore we can go ahead and use the instantiate method so this will now instantiate an enemy prefab at the spawn point position with the quaternion identity which means with no rotation so now once we've done that a new enemy will be created so we need to make sure that we increase the enemies that are alive with the next wave here but now that would only create one enemy but this next wave should create as many enemies as we have rounds at least that's the plan that i have here so we need to run a for loop here which will start at zero and that will check the length of rounds that we have so how many rounds did we have so far and increment this by one so this should happen for the amount of rounds we have played so far so the next wave let's say at the beginning is at round one so we're going to spawn one enemy in the second round we'll have two enemies and so forth so now let's just make sure sure that we're actually calling our next wave here with the round that we're at otherwise nothing would happen right so we prepared all of this beautiful code but it's never going to be called if we don't call it here okay so every time that the enemies alive are at zero the round should be increased so the round should be incremented and then we call the next wave which will have more enemies okay so let's go back to unity and let's make sure that our game manager gets all the details that it needs because if we look at it it needs to know the spawn points and it needs to know the enemy prefab so what i'm going to do is i'm going to go over to my zombies let me check my zombie here let's apply all changes really making sure that the zombie is going to be correct so let's delete this zombie because we have it as prefab it's really important or actually what we can do is we can even go to our assets we could even create a new prefab here so prefabs folder and i'm going to drag the zombie in here because i want to use the original prefab here as the zombie in my prefabs folder okay now inside of my game manager let me drag this zombie in there as the enemy prefab and now let's make sure that we have our five spawn points so what i'm going to do is i'm going to drag the spawners here well i can also do it writing spawner here so spawner 1 spawner 2 spawner 3 and then finally spawner 4. so now we have all of the spawner locations and now our enemies can spawn randomly and now by the way let me get rid of this default zombie that we have here let me save the scene and let's start the game so let's see if we can actually find an enemy in our game there he is whoa damn this dude is running after me so let me kill it or try to kill it before it kills me and as you have seen before i really suck at this game and i'm not sure whether our settings are correct for the size of the enemy so we will need to change that so now we have a little problem so i killed the enemy but it's never actually noticing well our game is never noticing that we don't have any enemies in the game anymore because this enemies alive here is never set to zero once we shoot an enemy so let's fix that in the next video because we need to make sure that this is going to be triggered in order to trigger the next round so see you there welcome back let's actually take care of our enemies so our zombies calling that they are dying so inside of the enemy manager we now need to take care of that so let's get an instance of the game manager in here so like this game manager which i'm going to call game manager like so and we can now get the game manager by dragging it in that will be fine and now once the enemy is being hit and destroyed we need to make sure that we are reducing the amount of enemies that we have so here we can go ahead and say game manager dot enemies alive is going to be decremented so we're reducing the amount of enemies that are alive because if you recall in the game manager we had this enemies alive variable that will be increased for every single enemy that is instantiated here so now what we're doing is once we are destroying an enemy we are reducing the amount of enemies that the game manager knows about this will make sure that the game manager is always up to date with the enemies that we have spawned so now what we can do is we can we can of course drag the game manager in in unity that's one way but i'm going to show you a neat little trick and that will be here i'm going to use this instantiate in order to create a new game object because you know this instantiate returns a game object object okay so what we can do is we can say game object and let's say we call this one enemy spawned or spawned enemy or whatever you want to call it and now we can use this enemy spawns in order to get its component so get its enemy manager script like so and set the game manager to be this current component so get component of the current game object that is called game manager so this is a neat little trick where we don't need to drag the game manager in manually but it will be done via code because as you might recall this enemy manager here needs a game manager so either we will drag it in manually or we just say okay this game manager script is going to be the game manager that we want to assign to you and that's basically it so now let's get back to our game and let's see if we have some enemies that are spawning that we can kill that then spawn the next round and stuff like that so let me see where are the enemies oh there he is so let me shoot it actually let me change the amount of damage i do because i feel like i'm way too bad at this so where was it i believe it was in the weapon itself so here let's go into root chest right arm right forearm right hand weapon so here the weapon damage let's make it boom 100 so once i hit once correctly the enemy will die so i'm making it easy for myself at least for testing purposes so let's see there is the enemy let me shoot it once and it seems like something is definitely not correct with me shooting it so now there are two enemies coming let me shoot those two okay done so let's see where the three enemies are coming from you see they come from different corners of the map holy moly it's getting scary already in round three what the freak so let me oh that my game is not working correctly yet so i need to definitely make sure that the animation is set correct or the shooting is set correctly okay that seems to work headshots seem to work okay that's good so there's the next enemy headshot i believe i need to be too close to them so i need to change the range that i can shoot boom boom boom headshots work flawlessly all right that's good good to know i actually the distance is fine whoa whoa whoa whoa whoa easy easy easy okay so now you've watched me play a shooter game for a couple of minutes i think it's oh it's enough so you see it was enough i was killed so i made it up to around i believe seven or six or so and i don't even know which round i was at and that is something that we need to fix and how can we fix that well we can fix that by adding a beautiful ui well it doesn't have to be beautiful and it won't be but it will be a ui so it will be a ui that shows us in which round we are how much health we have how much health the enemies have all this kind of stuff step by step so see you in the next video where we're going to get started with the rounds ui so see you there welcome back in this video i would like to implement the functionality where we can then see at the top left corner in which round we are so let's say we are at round zero then it should say round zero then once round one starts it should display round one so that's something that you can actually implement yourself already you will of course need to use the game manager's round number here in order to then display it over here so good luck achieving that okay i hope you achieved it and if you did then you can move over to the next video so what i'm going to make sure of is that i'm using full hd because then we are going to use the same numbers okay so you can just set up full hd i assume most of you have a full hd screen and then right click here and create a new text then you will get this new text here and i'm going to call this one round text so let's rename it round text like so now let's make sure that this round text will be at the top left corner because now it says new text here in the middle i would like it to be at the top left corner so i'm going to select this anchor preset and let me set the position to 0 0 and it will now be at the top left corner so now from there we can move it a little bit so let's go over to the round text and you will find that it is currently at the top left corner just outside of our screen so this white line is our screen and let's move it a little bit like so over here roughly like that so i believe values that are let's say around 90 or 100 something like that 90 minus 30 seem to be good for us so what i'm going to define the height for is going to be 50 the width of 160 should be fine let's change the text to so it's going to say something like ground zero then we can change the font size to maybe 40 or so let's see how this is going to look like 40 well maybe even more so let's do 60 then i assume we have to change the height as well let's try 70 and the width of 250 so this will be a little bigger now then the position also has to change so here let's do 150 well it really depends on how you want to do it so something around that space should be fine now you can align it towards the center but then you will run into the issue where the number would then flow over at one point so let's make sure we align it to the left and we can overflow it in both directions now also let's change the color to white so it will be more obvious now you could of course go ahead and create some cool color and some specific background for it and use a different font here but for our purposes this will be good enough now in our game manager in the script we can now use this round text so let's go ahead and set up our script for it to work so whenever we want to use text we need to make sure that we are implementing the ui namespace and then we can go ahead and just create the text object here i'm going to call this one round number and now we can go ahead and set this round number and i'd say we're going to set it every single time that we increment the round so here we are incrementing the round so let's change the round number to be whatever the round to string is going to be so this will just display the number for us so you could either say round plus round to string i think that would be the easiest way and even round column something like that then the text would display round then whatever round we're currently at as a string and would store it inside of our round number okay so let's save the script let's get back to unity and now our game manager should allow us to drag in the round text so let's go over here and we can see here round number text okay so let's drag in the round text here and let's see how this is going to pan out so let's shoot a zombie let's see where it comes from i'm a little scared there it is so oh i wasn't shooting okay i was outside of the game headshot there we are so it says round two now at the top headshot another headshot let's see if i get that one boom round three all right so now it displays the round number beautifully and that is pretty much it okay that's it for this video i hope you achieved this by yourself if you didn't no worries now you see how it's done so now a little challenge for you for the next video create the health ui so just display the health in a similar way as you do the round and i mean the player health here to be specific so see you in the next video where we're going to do that together welcome back so i hope you follow the challenge and try to do the same thing with the player health so the first person player health and you displayed it somewhere i will display it at the bottom right for now so let's go ahead and just implement it so therefore i'm going to require another text so let me just go ahead and create a new ui text i'm going to call this one health text and now let's change its settings up a little bit so i want it to be at the bottom right as i stated so let's set it to zero zero you can see it's there but you can probably not see it but it's it's there it's super small so let's change the height up a little bit let's change the y position let's see if we put it a little higher in the x position a little further to the left then we should be good to go 200 let's make it a 300 width like so so a position of let's say 100 minus 180 or maybe 150 something like that really depends on what you prefer i'm going to put it at around 50 for the y position let's make sure that the text will be in white like so now it's visible let's put it towards the right hand side then we would actually want it to be just still a little further to the left something like maybe even 200 minus 200 should be good so let's display zero health or 100 health okay that seems good let's do a gazillion health all right then it puts it into another line because of our limited width but i think this should not be a problem with our game because i don't want to display more than 100 health so now you can of course play around with the font size if you wanted to to be bigger such as for example 60 for the font size you also have to change the height or you have to make sure that you overflow here okay now we will overflow with our health in both directions now let's just make sure that our health text will actually be used in a script that would displace the health so the health is saved in the player manager here you can see it health is set to 100 so let's make sure to use this health here therefore we will need to make sure that we are using ui here so this namespace and then we can get the health of the player so here public text health text and let's use it like this and now we can use this health text inside of the hit method because that's where we are setting the health each time so here healthtext.text should be health to string but as i want to have the text health before it as well it will be the keyword health plus the value because the health is a float and we're just converting it into a string and we are going to display it in here all right that should be it let's save this script let's go back to unity and then let's assign this health text to our first person player player manager script here so let's drag over health text and let's run the game and see if zombies can now reduce our health at the bottom right hand corner so let them attack us and boom he attacked us and actually as it seems i am using it the other way around so i started with health first so we can also do it this way around so number plus anti-space health no empty space after all right you can of course also use capital letters here health this will be a little more visible or maybe even something like hp something like that all right so that's it for this video let's not forget to save our script here and i hope you were successful with this challenge see you in the next one where we're going to take care of the end screen see you there all right so now let's take care of an end screen and what i would like to do is i would like to add a layer here which will be slightly transparent but at the same time will be red and then we'll have a bit of text here saying something like game over round survive then the amount of rounds and then a play again button okay so let's go ahead and implement that therefore i'm going to create a new ui element and that will be a panel here like so and you see now it already has this transparent look and i'm going to make it something like this right here where it looks like okay well seems like we're dead so this will be our end screen let me actually put it so what we could do is either we could make this itself the end screen so i'm just going to do that and screen something like that and now inside of it i want to have a text so here ui text and let's call this one game over so this text will be in the middle i want it to be white text okay it will not be exactly in the middle but it should say something like game over and of course it has to be significantly larger let's make it centered and overflow towards all directions so we can actually see it so probably 80 or even more would be better so maybe something like 100 but then make it bold okay that looks a little better let's reposition it so i'm going to position it further towards the top something like let's say 300 should be fine you can play around with the width and height if you want to we're using overflow so it shouldn't be that much of an issue but still you can of course set it up to be let's say 120 for the height 800 for the width something like that now let's take care of our second text and i'm going to just duplicate game over i'm going to rename this rounds survived and this text will be saying rounds survived and i'm going to make it smaller maybe something like 60. i think this should look a little better let's position it at 100 let's see if that's going to be fine maybe 150 that looks a little better maybe also not bold let's see how that's going to look like well maybe we want to leave it bold but let's use 50 here okay so this will say rounds survived and now let's duplicate round survived and let's call this one rounds survived num so this will be the number displaying how many rounds we survived i'm going to set that to 0 by default like so and then let me position it a little lower as well so maybe not 0 maybe something like i don't know 70. i think this should be fine maybe we also want to change the font size here so that will be more obvious so 80 or even 90. so it's a little bigger okay so that will be our rounds survived text and the number all right and then i would like to have a button here as well so let's create a new button and that button should be a little lower so let me first of all change the text of the button and the name of it as well so replay button is going to be the name of it i'm going to change the text to something like play again let's also change the size of this button so currently it's one at 160 30 so let's use something like 460 maybe then let's reposition it so i'm going to use a y position of minus 120 something like that and the text should also of course be bigger now so let's use 30 here maybe 40 even yeah 40 seems fine you could make this button even significantly larger if you felt like it i'm going to make the text bold to make sure that it's going to be well visible okay maybe even say something like lay again like that with 45 as a font size so this should be good okay now we have the ui game over round survived amount of rounds and then play again now of course none of these things do anything and that's what we are going to change in the next video so see you there back let's take care of our game over screen we're not going to take care of the button yet but we're going to display the rounds that we survived as well as well make sure that we display the end screen because by default i want it to be disabled because only once we are dead the end screen should be displayed so let's go over to our game manager because our game manager takes care of the next wave and it should also take care of when the game ends so let's create a new method and let's call it end game like so and what do we want to do when we end the game well we want to display the end screen okay so let's make sure that we can find the end screen so i'm going to create a game object that will be my end screen okay now i can go ahead and deactivate the end screen and activate the end screen from this script so let's set it to active true so that it's going to be visible and now in our player manager we will need the game manager so let's go over to our player manager up here let's add the game manager because we want to call the game managers method now so let's create a game manager object here we're going to need to assign that game manager of course and now instead of saying load scene 0 here i'm going to call the game manager and its end game method because we use this method here this load cn0 at this point because it was convenient right but this is something that you should usually outsource to your game manager the game manager should control the game state okay so we can get rid of the methods that we're not using here in the player manager by the way so it will be a pretty short script so back in the game manager we can now actually take care of displaying the end screen as well as i'd say let's pause the time so time dot times scale let's set that to zero and then let's also make sure that our cursor is usable again so cursor lock state cursor lock mode none which means that we will easily be able to move out of the game in unity okay so this will allow us to move out of the gaming unity and then we will need to know how many rounds we survived so let's go ahead and create another entry for the text here so public text rounds survived like so and now we can use this round survived in order to display it in our end game here so we can go ahead and use rounds survived dot text to be the round to string so however many rounds we have survived that is what is going to beat this plate now now at this point we cannot reset the game yet which is fine well we got rid of this method that would do it and that was in the player manager right so we said end game so now we're going to add the button later on we're going to add this game over replay button here the functionality of replaying or resetting the game because currently we don't have a way to do it alright so now back in unity let's take care of our game manager actually knowing what is the end screen so let's drag that in there and let's drag in the rounds survived num to be the round survived here and now let's run the game and let's see if we can display the amount of rounds that we survived so i killed one monster now we are going to be in round two let them kill me okay there they are so now eat me and it seems like i still have a null point of reference let me check the game manager in the player okay that's good it's always good to test this so there we are the game manager let's make sure the player manager knows about the game manager as well and now let's start the game once again let's kill one zombae where is it there it is okay i killed one where's the other ones okay so now please kill me and boom so there we are bronze survived two and now what we want to do is we want to be able to play again so the game is frozen as you see nothing is moving and we can now potentially play again even though you saw we had the monster in front of our face and i could still shoot it which is fine not really that much of an issue but let's save the script for now and let's save the scene for now and see you in the next video where we're going to take care of the replay button welcome back in this video we're going to take care of the replay button or restart button however you want to call it so what we want to do is in our game manager we want to make sure that we have an option to reset the game and to reset the game we're just going to load our scene 0 once again so let's create a new method here public void restart and this method will do nothing too fancy it will just use the scene manager and will load the scene 0. so now this will of course only work if we have the right namespace so let's make sure we have scene management in our namespaces here so using unity scene management which will add this line here at the top okay so now we have this method restart which will just restart the game now there's something that we mustn't forget because if we forget that our game will work correctly so we also need to make sure that we set back the time dot time scale because if you don't do that then the game will be frozen and you cannot move you cannot play because in end game we are setting the time scale to zero and it stays there even if we reset the scene so we need to make sure that we set the time scale back to 1 and then we can move on all right so let's save this and now let's make sure that our replay button knows how to use it therefore let's click on the replay button on the right hand side let's add this on click and now we can go ahead and use the game manager here let's use the game manager the scene game object and then under functions you will find game manager which is the actual script and here we can use the restart button or restart thingy okay so now this will call the restart method let's save this scene and let's have a look if we can actually reset the game so let me shoot some zombies or let me actually die from zombies don't want to shoot any of them and there we are now let's play press play again and we can see we are back in the game even though we get this weird unity bug where the lighting is all bugged up so let's see if that works again okay play again and it works flawlessly quick pause the video that you're watching right now is just a fraction of the entire fps course and of course you're not only learning how to build a first person shooter but also make it a multiplayer game so you're going to learn a bunch more things than in this youtube video it's a seven and a half hour course and you can not only get the course but you can currently also get the book with a 50 discount definitely check out the link in the description below to improve upon what you're building in this video and become a real multiplayer game developer we're going to take care of the main menu therefore i'm going to go over to my scenes and as you see i have a scene here which is the game scene but now let's go ahead and create a new scene which i'm going to call main menu scene or just main menu is fine as well so inside of my main menu scene i want to have a panel here and i'm going to call this one main menu let's change the background color of it to black and make it less transparent so i'm going to make it 0 transparency so 255 for the a value and now on top of that main menu i want to add my text so i'm going to add a little text that's going to say something like incredible game so let's go ahead and call this one incredible fps zombie game okay and now let's make this significantly larger something like 80 let's make sure that it overflows in both directions that it's centered that it's a little higher and i'm going to use something like 300 so maybe too much 200 okay let's also change the color to white okay so it's going to say something like incredible fps zombie game that's fine now we can go ahead and create buttons so ui button here and i'm going to call this one start like so and let's also change the size of the button let's say we take a width of 400 a height of 100 or maybe just 80. 80 should be fine now we can position it as 0 0 0 that should be fine let's change the text a little as well so let's say play here let's change the font size to 60 60 looks good so now it's going to say play let's make it bold also yep that should be fine let's duplicate the start button let's change this text to exit or the name of it to exit it should also say exit instead now of course we need to position it somewhere else so and i don't mean the text i mean the exit itself so here let's use 150 something around that maybe 180 that looks good okay so now we have the start and the exit button and we have the title of our game incredible fps zombie game let's make sure that those buttons are also going to work therefore in the scripts folder i'm going to create a new script and i'm going to call this one main menu manager okay so let's check out the main menu manager so what is it that we want to do well we want to give those two buttons a functionality so we're just going to use a new method that i'm going to call start game which should only do one thing and that is use the scene manager so let's go ahead and make sure that we can use the scene manager i hope you recall how to do that we needed to add the scene management here and now we can use the scene manager to load the scene i'm going to load the scene i'm going to say load scene 1. so why is that well let's look at the build settings so here if we go to build settings i want to add the open scene as well so now unfortunately the main menu will be scene 1 and the game was c0 so i'm going to change that now so i'm dragging main menu to 0 which means that it will now be the entry point of our game and the game scene will be now at scene one okay so let's make sure that that is stored like that and now in our main menu manager we can just use the build index one now you could have also just called the name of the scene and the scene name was i believe just game so you could have also just said game here or game i think it was written like that but using the indexes is a safe way because let's say you change the name of the scene later on then this code wouldn't work anymore well in this case it will but if you were using the string it wouldn't work anymore and now we need to have another method which is going to be public because we want to use it inside of unity public void exit game and what this method will do is it will just use the application.quit method so this method will simply close our game so access the application runtime data and then quits the player application so this will shut down the game so close the game or quit the game maybe that's more obvious here based on the quit method okay so let's save this we have made sure that the code is ready but now we just need to make sure that this main menu manager is going to be inside of the game so let's create an empty game object i'm going to call this one main menu manager and now let's go over to our start button and let's make sure that we add the main menu manager here now i would like to use its methods but of course it doesn't have them yet that's because we didn't assign any so let's reset the main menu manager and let's drag the script in there now the start button has the main menu manager still in there but now we can access the main menu manager from here and we can access the start game method that's for our start button now let's do the same thing for the exit button you can pause the video and try it for yourself of course so add a new entry make sure that the main menu manager is dragged in there select the main menu manager here and select exit game all right and that should do the trick let's see if we can exit the game first and unfortunately we cannot at least not from unity itself let's check if this button is working therefore i'm just going to add a debug log statement here quitting game like so let's save the script and let's run it once again once it's loaded and let me press the exit key and you see it says quitting game and at this point we cannot really test it properly right but we can test the play button so let's test it let's see if we can get over to the other scene there we are so we're moving from one scene to another which is great so there's the zombie let's kill it and now let them kill us so here let's reduce or reduce our health and now let's click on play again and you will see we're sent over to our main menu screen so let's fix that real quick and that is in our game manager where we're loading the scene one let's change to our zero let's change it to scene one because scene one now is our game scene and c0 is our main menu scene and our restart method so far sent us to cn0 which now is our main menu scene so if we change that to scene 1 the game will actually allow us to also restart the game so let's test it real quick let the zombies kill us so let's play press play there is a zombie come on body kill me i always need to go away a little bit because the zombie can only kill us when we're moving play again and you see now we can actually play the game again all right so that's it for this video see you in the next one welcome back in this video i would like to add another button to our game over end screen here because currently if we look at it let me activate it we only have the play again button i would like to also have a button that sends me back to the main menu scene so i would like you to try to implement this yourself so pause the video and go ahead and try that okay so i hope you tried it i'm just going to duplicate the replay button i'm going to call this one main menu button like so and now this main menu button should also use the game manager but it should not use the restart method but instead it should create well it should move over to the main menu so let's create a new method public void back to main menu like so and what it will do is it will simply use the scene manager to load the scene zero and also we should make sure that the time scale is being set back to one because well endgame stops it or sets it to zero and we need to set it to one again okay at this point let's go ahead and save this script and try it okay therefore we need to make sure that this main menu button here also gets a different position so let me move it somewhere else i'm going to move it a little further down here and let's use -250 in my case should be fine let me change the text of it so it should say something like back to main or to menu it should be fine or main menu not sure if that's good back to menu should be okay then it also fits into the button size otherwise would have to change the button size and all of that stuff so now let's just make sure that this button here is not going to use the restart method but instead it's going to call the back to main menu this one here okay and now let's test it well actually we need to make sure that first of all the end screen is deactivated by default all right now let's test it let's get killed by zombies and this would be a lot easier faster if we had less health or the enemy would do more damage so kill me there we are now let's go back to the main menu [Music] and there we are now let's play and it works so now we have a working game even though there are still a bunch of things that we can improve but overall the game is working we have a shooting system we have running enemies with animations we have rounds we have a jumping feature a little map and so forth thanks a lot for watching this video i hope you enjoyed it now you're one step closer to becoming a unity game developer and if you haven't liked the video yet please do so now as well as subscribe and also make sure to follow along in the playlist to become a real unity developer and if you want to fast track the whole development process of becoming a developer then definitely check out our unity master class in which you're going to build a bunch of games and while doing so learn everything you need to know about game development and well have your first couple of projects under your belt so check it out the link is in the description below you will get a huge discount and i hope to see you in the next video
Info
Channel: tutorialsEU
Views: 1,894
Rating: undefined out of 5
Keywords: Tutorials, Tutorial, Programming, Course, Learn, Step by step, guide, development, programmer, video course, video tutorial, learn how to, how to, indie game dev, unity fps, indie game devlog, gamedev, unity tutorial, unity3d, level design, indie game development, unreal engine, brackeys, unity 3d tutorial, game dev, learn unity, game development, unity game development, unity beginner tutorial, unity game dev, freecodecamp, codemonkey, unity official, 2021, unity fps game, devlog, game
Id: Jk85v08gmtc
Channel Id: undefined
Length: 218min 20sec (13100 seconds)
Published: Tue Dec 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.