we are going to build a full game from scratch this is a culmination of all my experience over the last 5 years I'm going to streamline this process for you if you stick with me in this video you will be proud of what you have created here is our overview we're going to build a 3D environment and characters in a program called blender we will then use General enage manipulation program to texture this environment and her models we will then export this environment plus models to our game engine called gdau here we will build and code our game it will be a slim down version of Nazi zombies our enemies will chase us down and we the player will shoot at them and get points FPS style it sounds like a lot but I promise you this is the fastest way to learn what I have learned in 5 years I'm condensing all my knowledge down to get you in the game as quick as possible and avoid the frustration that plagued me sometimes you don't even really know what questions to ask so you don't know how to advance forward I'm going to clear all that up and just get you moving as fast as possible first let's talk about what we need we need a a program to create the game called the game engine this is pretty standard practice Dark Souls uses the Havoc engine Gears of War use the Unreal Engine and Fallout use the creation engine so why don't we use something like these well because unreal is expensive to publish for indie games and others are proprietary to their companies they won't just let you use them so in terms of free game development right now gdau is at the top of my list we can get the download from gdau engine. org downwinds I'll leave a link Link in the description so you know where to go download the regular release and do and not theet version the net version is for CP users which we are not next we are going to download blender I'll again leave a link in the description blender is a 3D modeling software we can use to create 3D objects for our game world and animate them so we will animate our characters using blender and create our game world too completely free you can download it from blender.org I'll leave a link finally we need which is is an image editing program images wrap around our 3D objects we create in blender and they end up in the game world as our textures we can create cool images to use within to make our game look interesting those are all the downloads We need they're all completely free and now we can get creating here's how the process is going to go we're going to make all of our 3D objects first in blender we'll get the texture straight in and then after all that is done we'll export everything to gdau and get our game coded all right so you might be opening blender for the first time but that's okay because I'm going to teach you how to use blender step by step by introducing you to individual elements that build into each other first we are going to open up blender you'll probably get some setup dialogue to select the language and stuff after that you can go to the default scene option which gives us a new basic scene so this is what blender normally looks like with a default scene a cube in the middle a light to the left and a camera to the right if you are completely new to blending you might find it hard to understand what you are looking at for now do not worry about the panels to the right side of the screen we will address them later we want to focus on the main part of the screen with Cube the fundamental controls of blender are this mouse scroll to zoom in and out middle Mouse click to rotate around the center of the screen shift plus middle Mouse click to drag the screen to that direction clicking on the Gizmo at the top right of the screen will flip your view to that orientation these are the simplest ways to move your view and blender if you want to see all the keyboard shortcuts for blender you can view them here there's a link in the description however we will learn more shortly selecting an object to select an object we need to click on it and or drag a selection box over it you can select multiple objects At Once by holding shift but for now just select the cube when the cube has an orange outline it is ready to manipulate pressing G will allow you to move the cube freely pressing escape will cancel that movement if you press G G and then press X Y or Z then you will move only on that axis if you press G then hold shift and press the X Y or Z Keys you will lock that axis and the cube will only move in the other two so if you only want to move the cube left or right or forward or back and not change its height you would select the cube press G and then shift Z so that the cube will not change in elevation but will move along the ground the S key operates the same way as a g key which we can use it the same way but it will scale instead of move rotation can be achieved by doing the same thing with the r key we can rotate on any Axis or by locking the axis like we have done previously with the other settings so we can now move rotate and scale the cube any way we want let's do all three in a random fashion so the cube is in a different spot from where it was any which way as long as it's different from where it was now you will notice if you press the S the G or the r key and then select the access using z x or y you can tap the axis again to move along the local axis of the cube as opposed to the x axis of the world this works for scaling movement and rotation as well it can be useful to get things into position so you want to keep that in mind I only point this out because it confused me at first I didn't understand what was happening so if we don't like our cubes location rotation or scale anymore we can return them back to normal by pressing alt G for location alt R for rotation and ALT s for scale this will return the object back to its applied location rotation or scale on the flip side if we did like these placements how could we keep them well we need to apply that specific property we do this by pressing crl a while having the cube selected this will bring up a menu where we can decide what we want to apply once applied the cube will return to that spot when alt G is pressed the same goes for Applied rotation or scaling they will become the object's default when applied to give you an overview this is how blender works you create objects like the cube you see in the middle then you can edit those objects in different ways to create new shapes simple shapes like cubes or Advanced shapes like dragons we refer to these shapes as meshes a mesh is made up of faces and the faces are made up of points called vertices and in the simplest terms the computer knows which way the vertices are facing and where they are so it connects them and creates faces that make up the whole of the mesh the more vertices the mesh has the longer the computer is going to need to process it hundreds of thousands of vertices can be used in a game but generally it is best to use the fewest amount possible to achieve the look you want for your game having less stuff to display cuts down on the work your computer has to do to Output all those Graphics Lighting in viewport shading so we understand the cube mesh a little better but now let's take a look at the other objects first let's examine the light to the right of the cube you will notice that there really isn't any light coming from it this isn't because the light isn't working it is because the display mode we are in to see the light we need to press and hold the Z key and move our Mouse to select the different viewing modes we are currently in the solid View and we want to switch to the top one the render view so move your mouse up and release the Z key to select that view after releasing try selecting the light again and moving it around with the G key the cube should project Shadows now and the light should be visible we can switch freely between the views by pressing the Z hold or by using the buttons at the top right of the screen often when manipulating or editing models it is common to switch viewport shading frequently to get a more cohesive view of the scene continuing with the light switch to the render viewport shading Z hold and mouse up select the light and look to the right to see the panel and that holds all the objects properties with the light selected click the green icon on those panels that looks like a light bulb if you hover over it it says data object data properties click on this to be able to adjust the lights properties the main properties to play with here are the power which makes it brighter the color which changes its color and the type of light selected by the icon you can choose the light and play around with the different options I will keep mine on point for now and leave the settings about the same it is not super important for our purposes let's talk about the object property panel a little more on the set of icons where we selected the green light bulb icon there is more to see and understand these are added options for whatever selected object we have click on the orange Square inside of the box when hovered it says object object properties click on The Orange Box to the panel and the panel to the right will change so you can see the transform of the select Ed object the transform is the position rotation and scaling of that object you can change the values here to manipulate the object the same way we did earlier using the G S and R Keys the panel is good to understand but we will not have to adjust anything here for now the icons Above The Orange Box on the same strip are not properties of the selected object instead they are properties of blender or the entire screen or the world we will go into depth on them later and when we need to use them editing the cube we are now going to edit the cube so we start by selecting the cube then we press the tab button once this will enter us into edit mode we can press the tab button again to return to object mode we can also change the modes by selecting them from a drop- down at the top left the modes you can change will differ depending on the object you have chosen a light will have no edit mode but a mesh should always have an edit mode for instance in edit mode we can manipulate the mesh that makes up the shape of our object if we look at the top left we will see some icons that represent the vertices the edges and the faces of our mesh select the edges the middle option and you will see we can manipulate the edges of the cube you can select a single edge by clicking on it individually and holding shift to select multiple edges with the edges selected we can use our trusty GS and R keys to move rotate or scale just like we did in object mode if we return to our top top left menu and select the face icon the rightmost one that looks like a square we'll be able to select the faces of the cube the same rotation scaling and location methods are available to us here by using our GS and R Keys again we will examine the last option on the menu to the top left the vertex selection here we can move the verts that make up the edges giving us very fine control of the shape again using the GS and R keys while still in edit mode we can look to our left and view the tools available to us while editing our mesh T will hide and show our editing toolbar from the top down I will be explaining the tools the select box this will allow us to choose our method of selection we default the Box selection but we can change things to make it more conveniently we might use this later on the cursor the cursor is basically where your viewport is looking at regularly don't mess with this for now just leave it where it is the next four options are just the moving scaling and rotation buttons that we used earlier with the GS and R Keys it's just another way to access them further down we have annotations which just allow you to annotate the creation uh you have made I have never used this feature the measure tool is below that and it does exactly what it says it measure stuff I really don't use it much but it can be helpful add Cube this will allow you to add another Cube to the mesh and that Cube can be manipulated after creation as well extrude region this one is very useful you can use it to continue a shape or extrude it it adds more geometry to our mesh we can extrude a single vert an edge or face inset region this will create more geometry on the mesh by creating a shape inside from the outer edges bevel bevel will bevel the edges or around them depending on the setting of The bevel Loop cut Loop cut will create a loop all the way around the mesh can be very useful for modeling the knife tool is the last one we will talk about and that allows you to cut vertices into a shape it's very situational but pretty useful the other tools are not really going to be used in this tutorial and they're more advanced so we're not trying to master blender here we're just trying to learn enough to make games the first thing we're going to be making is a torch to light up our scene in the game to begin we just want to go ahead and switch back to object mode after that we will select the cube and press X to delete it we are then going to create whatever shape we want at the top left near the mode selection there's an add button when clicked we move to the mesh option and follow the dropdown press the plane to create a new plane mesh now that we have our plain mesh we want to edit it so let's switch to edit mode let's use the menu on the top left again select the face selection now select the top face of the plane and press e to extrude the plane's face up a short distance this will be the base of our torch pressing e here is the same as selecting the extrude tool on the left side of the toolbar this is just much faster notice when we pressed e we were automatically locked onto the local z-axis of the mesh to move the Extrusion freely press the Z key and that will unbind it from the z-axis allowing it to move everywhere however this locking is what we want so there's no need to worry about it for now let's extrude again and we should have a taller Cube shape after clicking to finalize the second extrude with the same face selected press the S key to scale the top face inward creating a nice slant shape we will repeat this process to create the elongated skinny section leading to the torch tip we can flare it out at the top to make the holder for the Embers to create the cup shape at the top we can select the top face of the torch and press I to create an inset drag the mouse to choose where the inset stops click on the inside squares and press the e key to extrude the square downward creating the torch cup using the I for inset here is the same as using the inset option on the toolbar our torch modeling is now complete however we want to add a material and a texture to the torch to make it look cool so in blender we have materials which are found on the tab that looks like a beach ball in the object properties panel with our torch selected we can click the material tab to view the materials in use on that object currently there are no materials on that mesh so we need to create one press the new button on the material panel a new material will be created and you can doubleclick the material to rename it I will name this material concrete if we scroll down in the materials panel we can see the attributes that make up the material let's change the base color by clicking on the color selector next to the base color attribute if you are changing the color and the object is not changing colors you may be in the solid shading preview use the Z button to switch to the material preview view like we did before you should see the color change now we want to have two different materials on this torch so let's click the small plus sign near the top right of the panel this will create another new material that we can Name by double clicking on it just like before now that we have the material created it is important to assign it otherwise it won't actually appear on our model to do this we want to go to edit mode and choose the phase selection option we will then select the the faces we want to apply or assign the material to we can select multiple faces in a loop by using the ALT key select the faces vertically click towards the uppermost or lowermost section of the face while holding the ALT key to select horizontally looping faces select click to the left or the rightmost section of the face while holding alt when you have the face you want selected return your cursor to the material tab make sure you have the correct material selected and click the assign button the new materials should now be assigned to the selected faces now we have materials and we need to give those materials textures a texture is just an image this image will wrap around the shape and give the object its intended look in the game world if you want free textures you can go to texture Haven or opengameart.org we will be creating textures for this game in because it is good practice let's put blender on hold and jump into when we first open up we can see we have an empty screen with a mascot peeking from the bottom we need to navigate to the file option at the top left of the screen select new and then create a new image dialogue will pop up and we will set the parameters of the new image we are creating let's do a square texture that is 500 by 500 pixels before you click okay click the advanced option plus button and navigate to the fill with dropdown from the dropdown select the foreground color option now before accepting choose the foreground color near the top right darker colors work better for what we are attempting I will use black once the color is selected click okay in the dialogue and create the new image now that we have a blank canvas we will grab the paintbrush tool choose a color and paint a bit I like to dab a bit instead of dragging that seems to produce the results I want I will use contrasting colors select one of the Cloudy paint stamps I will place a few in random areas around the square I like to choose a few few different brushes and maybe rotate them a little bit as well for added effect I will repeat this with a different color probably a lighter one to add a little more contrast once done I will select the colorize option from the color menu at the top this will allow me to recolor everything to a more muted concrete tone I then like to play around with the exposure until I get something I like normally upping the black level and the exposure after this we need to go to the filters drop down hover over the maps option and select the tile seamless option we now have a seamless tileable texture we will now export this to a folder for use in blender it is important to note that saving a project in does not export the image that we need if you save the file it allows you to open that file in again to get our PNG we need to export the picture saving is still recommended however to export a picture select the file option at the top left of the screen then then click the export as option change the name of the image to the file type you want I want to use pngs let's choose that and click on the export which gives us our texture that we need before we leave let's create a normal map texture that will help blender add more definition to our 3D object with the project still open select the filters option at the top again hover over the generic option and select normal map which will turn our image blue with what looks like red veins running through through it this is our normal map and it will help us create more definition on our 3D object we will export this image and jump back into blender the Shader editor Tab and adding our images now that we have our texture it's time to place those textures on the materials inside a blender let's choose our concrete material first we need to switch to the Shader editor tab we do this by clicking on the tab at the top of the screen we won't use all of these tabs but we will view more later the importance of the Shader editor tab is to easily adjust your materials in blender materials can use a node based system that we see on the bottom half of the screen if you haven't done so yet you can try clicking on the outer edges of panels to drag them bigger or smaller nodes sound complicated but they are just attributes we attach to our material what we are seeing are the same properties that we have on our material panel to the right but with nodes in this view we also have added functionality for the material like adding image nodes that is what we are going to do now let's click the add button at the top of the node panel this will result in a drop-down menu where we select the texture submenu and then the image texture option this will create for us an image texture node with which we can load our image we created earlier in click the open button on the image texture node and select the texture you want to place on that material your image will most likely look stretched and warped on the shape don't worry we are about to fix this UV editing and what are UVS there is nothing wrong with our texture instead it is the UV map of the object that has problems if you don't know what a UV map is don't worry we're going to learn now let's change our tab again to the UV editing at the very top we can see our image to the left and our object to the right our object might be in solid shading so let's hover over the side of our screen and use the Z key to select the material preview shading okay now we can explain what is going on here and what are UVS UVS are the mapping of your texture onto the 3D object here are a few examples I found online to illustrate the principle we are taking the texture that is a 2D image and telling blender how to lay the image on top of the 3D mesh this is called a UV map so why is our UV map all messed up because our scaling is non-uniform on the object we scaled certain faces of our mesh when we were creating it and it means the UVS are confused on how they should lay we can see this if we click on the top faces of the torch the flat shape of the uvv to our left resembles the face on our model to our right if we now click down on the Square section where we scaled and extruded you can see the UVS do not resemble the shape at all all these issues have a simple fix simply return to object mode make sure the torch is selected and hit control a to access the apply menu now we can apply all the transforms which will fix our scaling issues so our model is not fixed just yet our scaling is now corrected and we need to tell blender to remap the UVS on the object this is called unwrapping the object let's prepare to unwrap our object Now by switching to editing mode so we need to add seams to our model to tell blender how to un wrap it properly a seam is where the model will have separation on the UVS it is easier to show you than to explain we want to select the side edges of the mesh and then mark them as seams we can switch to Edge selection at the top left and then select the edges we want these are lines our UVS will separate at when unwrapping just stick with me and it'll make sense we want to select the outer edges of the model to do so we use a combination of the shift key select multiple edges and the ALT key to select entire Loops this can be more complicated on a complex model and we will show an automatic way to do this but having a moderate understanding of UVS is important for a game developer once we have them selected let's mark them by right clicking on them and selecting Mark seam the lines now have an orange highlight to them denoting them as seams now we have added seams to the model we can finally unwrap it in edit mode we can press a to select all the geometry on the model this should highlight the entire torch we now need to access the UV options and the editing viewport ribbon if your screen is concealing the options like mine is click the ribbon with the middle Mouse button and drag it to the left we are looking for the UV button click it and then select the option unrap at the very top of the dropdown your model's textures should now look a little better on the model you can click on the faces of the model to edit them individually I'm okay with this for now let's add our normal texture to our material and be done with it but before we do that I want to demonstrate the automatic way I alluded to earlier we can basically ask blender to project the seams onto our object by going to the UV button again in the editing menu and choosing the smart UV projection make sure you have the entire model selected or it won't know what you want to project it attempts to unwrap your shape by creating its own imaginary seams this works pretty well for simple geometry adding the normal texture so this is the same as when we added the image texture a few minutes ago first we will go back to the shading tab at the very top of the screen next we will click the add button in the node menu select the texture submenu and then select the image texture option this creates the image texture node so we can select all our normal texture go ahead and do this now now we cannot just plug this node into the material directly we need a helper node in between to interpret the data correctly so we click the add button again and this time click on the search option type normal map and then select that option we then plug the normal texture into this node and the output of the normal map node goes to the material in the normal slot this gives our material an understanding of how light should be applied to the object we will not add any other maps to the material if it is not needed I'm trying to introduce everyone to the ideas at a lightning pce without being too boring adding more images or maps to the material will make it look better by adding more definition we're not trying to make the next Skyrim here so we're only going to add these two maps and we're going to leave it where it is next we will be finishing our second material which will take much less effort this is going to be a golden metallic type deal so let's just apply the same normal map as our first material but use a golden color you'll see what I mean in a second first we want to select the second material on our mesh once we have it selected let's look at the options we have the color is easy to adjust let's make it a yellowish Brown Next we are going to take the metallic value and set it all the way to one because this is a metal object we can now adjust the roughness of the object which will change how smooth the object looks you can put a height map in here instead of adjusting this attribute which would make the material look better however it is beyond the scope of what we want so let's just move it until we get something we like now let's add the normal texture let's return to our first material concrete now we should box select the normal map and the image node containing the normal map image once once you have it selected on your keyboard press contrl C to copy those nodes now click back to your second material again to return to it you can click inside the node selection now and press contrl V to paste those nodes you can then hook them up and our normal map is ready to go so now we have a rough overview of how blender modeling goes let's expand our knowledge a little further so we can now create and modify shapes within blender we can add textures to those shapes as well so the basic idea is that we make shapes look like things and then we put textures on them to make those things look more like things and that's basically how it goes uh the final pillar of simple modeling with blender is the use of modifiers we're going to create a new scene and then take a look at modifiers we are just going to use the default Cube and add some modifiers to see how they work to access the modifiers you must have a mesh selected and click the tab that looks like a wrench then choose the add modifier dropdown and choose from the list there's a long selection I will only ever use a few of them we will only cover the few basic ones that are needed for our Game Dev Journey let's go ahead and select the mirror modifier the mirror does exactly what you think it will mirror the shape to the selected axis we split the cube using the loop cut tool and delete the vertices so the mirror does all the work for us this can cut in half the work that we have to do when modeling when I have symmetrical objects it is much easier to only model half or even just a quarter of the full shape if you are using the mirror modifier in this way it is important to take note of the clipping and merging options the clipping feature will merge the mirror vertices with the actual geometry making your model watertight so there won't be cracks between the faces the clipping checkbox enables the feature the merge value is the distance between two vertices before they become one for our purposes we only have to turn on the feature and not adjust any of the other values I don't think I've ever had to adjust this value it's pretty small already we can also mirror the entire object around another object to demonstrate let's add a cube first and drag it to the left with the G key also we add another mirror modifier to our star shape and this time we will place the cube into the mirror object slot alternatively you can select the shape with the eye dropper the star shape should now be mirrored over the cube in the axis we chose we can show or hide the modifiers in each specific mode by clicking on the icons near the top of the modifier panel let's remove the secondary mirror modifier for now to make the example simpler finally we can click the drop down on the modifier panel to select the apply option applying will make the mirror modifier into real mesh in the viewport you will notice we can no longer edit the mirror modifier options applying the modifier removes it from the stack meaning it is no longer editable the geometry is now created at this point we can still contrl Z to undo if this was an accident generally if you don't need to apply a modifier yet or you are not finished with the object it is best not to apply the modifier before we export we will need to apply all modifiers because they will not transfer to the game engine or any other program these modifiers are specific to the blender program subdivision surface modifier we will look at another modifier for more reference this one is called the subdivision surface modifier which sounds very complicated but it just increases the amount of of geometry on your mesh we will apply it to our star shape to understand what it does we can have multiple modifiers going on at the same time and even change the order as needed after adding the subdivision surface modifier we can see the surface of the model has been subdivided into more chunks the edges become rounder because the mesh is now interpolating or estimating the middle of the divided surfaces we can change this by altering the mode of the modifier to simple instead of cat Clark in simple mode our shape will still be divided but the edges will not be rounded like before we can change the amount of subdivisions by changing the value in the levels viewport we could also apply this in the same way we applied the mirror modifier there are lots of modifiers we could use but those are the two I use most often if you are new it's best to experiment around and see what other modifiers do for now we have what we need to start modeling so let's begin our level construction making the temple so now we are going to create our game world we are going to do a zombies clone so we need an arena type deal I'm going to show my planning technique and then I'll show sped up footage of me creating the map in blender I may highlight some areas in the process just to demonstrate how to accomplish certain things you can create your own map using the modeling techniques we've shown so far all right so we're making the map now uh you can skip past this part if you want this is just kind of um to show you how I did it and here it was kind of stupid to model both sides because I end up just cutting it in half and using a mirror modifier so I mean that's usually my go-to I don't know why I didn't do it from the start here um it's not a very big map but I wanted to give a couple challenges for the path finding for gdau I wanted to have some hallways which I do and then I also wanted to have the bridges and I think what I'm going to do is just make a flat mesh to go on top of everything and um uh it'll make more sense when I do it but I'm going to have that be what the character collides with and then all the other meshes are just going to be there just for show and we'll have the um Collision mesh be separate I think that's a good idea so I'm getting pretty close to oh I'm doing some planks right here putting them in an array and then I'm just going to have these floating steps that are like a purple stone or whatever it's going to be like a space type thing with some type of um liquid flowing underneath it is what I'm going for you put the camera into view and I think it's always good to get a viewpoint on your level uh with your camera and then you can hit o to return to it so it's always you know you can press o and get that vantage point so here I kept with the geometry for no reason and then I had some textures oh yeah here I started putting all the textures on and I basically just grabbed fill patterns from uh and then you know changed the color a little bit or edited them um I mean you could go as crazy as you want with the textures and make your own or have an artist make them or buy them or you know however you want to do it uh I'm just doing this the fastest way I know just to demonstrate what like textures are and like that I don't know my Approach towards Graphics is that they should just look good enough to be able to understand what the thing is and what the thing is is abstract building so so I think that's what it looks like to me I'm kind of along the PS2 lines of just make it look good enough I never really gave a about HD graphics but I'm not a little Zoomer so what do I know uh here um the scaling on these is all up so I have to go back and apply the scale and that makes them look a little better I do like this ground texture I think that looks it's pretty cool even though I didn't really make it I just copied and pasted it but I really like that looks pretty sick uh the goat texture I don't know why I was trying to put that in there it looks like um I thought maybe it would look cool but it does not so I eventually give up and you can watch that in just a second I just thought this is a good demonstration ation of UVS and how you can map them and try and make but you know sometimes it's just not worth all the effort especially if you're doing an indie game I mean why but yeah we plug that in right there uh that looks pretty good and then I added a background texture in the world environment and that's how that stuff appears in the back on the rendered uh rendered scene but yeah then I just add this big plane and subdivide it a bunch of times and then we add a uh displacement modifier with a noise texture so it kind of just kind of noises it all up moves it all around I make some big rocks to put in the background so it's kind of like a almost like a query waterfall and outer space type deal which is what we're doing um I think it looks pretty decent for the amount of time I put in and I mean that's not really the point the point is that you're making a level and you're learning how to use blender and all that so honestly if I was going to make a game I'd probably have an artist do it because I'm not really I'm not really an artist I'm just uh some uh Guy online so yeah we have our finished product here uh I look pretty much like the way it turned out it's kind of like I don't know kind of like unreal tourn is um yeah I might uh add a little more to it we're going to add some items have items on the wall just like zombies where you can like you know buy them off the wall and we're going to add that I'll probably do like a shotgun a pistol and like an SMG or something um we also might add a little door trim uh maybe some baseboard and then maybe just some like space up on the walls that'll probably be cool and then of course once we get to gdau we're going to have to add all of our own lighting because the lighting from blender doesn't really carry over so but um yeah it's going to be pretty pretty freaking sweet I made it kind of circular and the enemies I think we're going to uh go with something close to like Stephen Kings the langers um looking cuz it'll be easy to make and blender so now that we have our level I want to create some Collision for the character to stand on we could just use the geometry that is the ground but I prefer to create a plane just above the ground so we can simplify everything I just created a plain mesh in blender and then extruded it to be roughly the shape of the ground we are now going to export our model and begin building our game in gdau but before we export we must create a game to export into so let's put blender to the side and open up gdau once we are in we can choose the new project icon at the top right choose a name for your project and then click the create an edit button to create a new folder and open the project we now want to create a new folder for our 3D models to be placed in you can take whatever approach you want to organizing the file here I'm going to make an assets folder and then make a folder for the level and characters it's up to you this project is pretty small so it doesn't really matter that much we don't have a lot of organization we now have a place to put our models from blender so let's return to blender and then export them to this folder to export the project we can go to file select export and choose the gltf 2.0 option option this is a GL transmission format file they are 3D files used in games and web applications we could use other formats but I prefer this one for reliability let's export to gdau and then check out our model don't worry if everything isn't perfect we can adjust the materials within gdau we can also export more objects to our model if we want or fix our model and readjust our whole Arena and then reexport this is not a f version by any means and we might always improve upon it for now we're just going to keep moving forward all right so welcome to gdau gdau is a game engine and game engines make games gdau looks very complicated to start but there's actually much less to look at than in blender we will work our way around the screen and explain what everything is now if we look to our upper left we have the scene panel which shows us all the things in our scene these things in gdau are called nodes we will go more into depth after we explain a little more if we click the import tab we can alter how a resource is imported into our scene we really don't need to change anything here yet but we could use this to make a sound clip Loop or edit other media before it's entered into the game engine below these panels we have the file system tab which allows us to view the files in our project this is a pretty simple interface you can rightclick to edit file names or move files it is better to edit files through here instead of your regular file system it keeps gdau in the no on where your files are the viewport to the right of that in the center of the screen is the viewport this works very similarly to blender where we can move around and use the 3D Gizmo to our our upper right to move our view to that position we can also hold the right Mouse button while pressing the W ASD keys to move in firsters mode in the viewport there are many tools in the ribbon at the top we'll address these later below the viewport there is a panel that changes based on your selection at the very bottom if we click the output tab we can see all the text output from the gdau engine this will be important when we start coding but for now it's just a bunch of text we can click through the rest of the options down here or double click the option it's on to close the panel alog together we will go more into depth on these menus later but for now we'll just minimize them to the right we can see we have an inspector tab which is used to inspect a node once it is is selected all of the nodes properties show up here and can be manipulated if we click the node button next to that at the top we can view the signals and groups of that node this will be covered in the coding section of the tutorial if we choose the history tab to the right it will tell us all the changes we have made to this node this can be useful if you forgot what you have done and want to change something back the center menu is at the very top it has 2D 3D script and AET lib buttons and this will change our main screen context the 2D and 3D buttons are to change the respective viewports if you have a HUD that would be on the 2D section and then if you have a 3D character moving in a 3D scene that would be on the 3D section and you can change between them easily here the script button brings up the coding editor so you can code your game the asset live button allows you to access all the community plugins and assets made for gdau we won't be using this because we are building everything from scratch the final section to talk about is the menus at the very top left the scene menus are like the file menu in a Word document we can save our scene or open another scene here to the right of the scene menus we have the project menu which allows you to edit project settings here we can add input from our keyboard to make the player do things or we can change screen settings or FPS settings on the actual game engine the debug menu allows us to turn on and off debug settings so that we can see things a little clearer we can do things like turn on and off Collision visibility so we could see where maps are maybe colliding and where our character is falling off of things the editor settings are next and they allow you to adjust the actual gdau editor settings to your likings uh I normally leave them where they are the final option is the help menu which is very useful once we start coding I'll explain why shortly now that we know our way around gdau let's make our first scene at the simplest level scenes hold our not nodes our nodes are the things in our game like the environment the player and the enemies and we run the scenes to play our game if you had an original Mario game for the Game Boy you could think of the scenes as levels for now when a scene is called upon to run or be played we call this instancing so we could say the scene is instance or we are running an instance of that scene let's focus a little more on some of the nodes and we'll work our way up there are many types of nodes in gdau that are used to make different objects in the game world we could have a node that represents the player a node that represents a chest and even a node that represents the player's health bar the node system is unique to gdau and it's one of the reasons that I enjoy using the gdau engine it simplifies things and I'll walk you through a typical scene to display what I mean we can click the plus button to add a new scene let's select the 3D scene which will create us a node 3D let's press control save to save this scene you can choose a place to put the scene from the menu once we have our scene we can press the plus bar in the scene panel to add another node to the scene let's do so and look at the menu we are given all the nodes available to us are displayed here in general red nodes are for 3D purposes and green or blue nodes are for 2D purposes we will have to use both in our games 3D nodes for the player and 2D nodes for the Player's heads up display we want to make a simple Cube mesh so let's get to the search bar and type in mesh instance 3D this is is the node we want after we select it we click the create button at the bottom to place the node in our scene we don't see any mesh yet but we do have the mesh instance node added as a child of our node 3D if we select it in the scene panel we can view its properties in the right hand inspector panel if we look at the mesh property on the panel we can see that it is empty if we click on it then we can select an option from the drop drop down let's choose the simple box mesh to start with we can click on the cube in the inspector to bring up more options now we have our Cube if we choose the material option we can choose to add a new standard material to our Cube if we click on the material slot we will be able to edit the material options let's choose the albo option and change the color just to demonstrate how it works looking through the options we should see familiar names we have the metallic option the roughness option and the normal map just like we had in blender we will examine this further later for now we will continue our orientation to gdau we can close the material options by clicking the material slot again after it is open we can do the same to the mesh to simplify our inspector panel let's click now on the transform section of the mesh instance 3D this panel holds our objects place in the game World from here we can alter the position rotation and scale of our object let's create our first scene to run in the engine we return the cube to its default position by pressing the return button in the inspector panel or by manually changing the numbers to zero let's also rename our Cube to Coal Cube let's click on the Node 3D at the top and click the plus to add another node to our scene this time type camera 3D into the search bar and select that node press the create button at the bottom to add this camera to our scene this camera is how we will see the world at runtime it will make more sense in a minute for now let's move the camera so our cube is in view to make this easier let's add a secondary viewport Click The View view button near the top of the screen select the two viewport option let's make sure the camera is selected first then in the bottom viewport check the camera preview box now we are seeing what the camera will see we can move the camera either using the transform Properties or the viewport editor move it to a good position to see our Cube we are going to add our first script to the cube to move it around and we want the camera to be able to see it so we have our scene and we want it to be a playable game how do we do that well first we go to the top and we press the Run button the one that looks like a play button we will probably get a message saying that there is no main scene to find and we can select the current scene by pressing select current this sets our current scene to run every time we press the play button we can change this later for now if we want uh for now it is fine we can press play now and we can see the game world with our cube in it this is how gdau works we create scenes and then we can run them with the play button up there we can link scenes together and have them play one after another to be levels or areas loading in and out of each other and then we would eventually publish and Export this entire game and it would take all of our scenes which we would be linking together through our story line and through code and that would be the entire game that's a little abstract but at least that's pretty much how it goes so let's add a script to our Cube object that will make it move around let's select our Cube mesh and then select the add script button to attach a new script to it when we click the button we are greeted by the menu we will go through the options really quickly although we don't need to change much if anything the language option allows us to change the language we are coding in by default we are set to use the GD script language which is the language of the Gau engine it is best for beginners and good for what we are doing so we'll stick with that for now the inherits box tells the engine what kind of script it is it is placed on a mesh instance 3D node so it will default to inheriting from the mesh instance 3D script we won't really need to adjust this and it can get complicated pretty quickly so for now just understand that this inherits thing just means the engine knows what node this is and how to handle it the class name is an advanced option we don't need for this tutorial so we'll just skip it the template option chooses whether you want some basic stuff added to your script to start you off it is a good idea to leave this on for now because it is very helpful for beginners we will see in a second it is the same as having a template in a Word document but just for programming the built-in script is kind of a weird option it will save the script in with the scene it is mainly used for fast prototyping when you expect to be throwing away the script and the scene later so you can avoid clutter by saving them together and deleting them together we want this to be unchecked so we create a script separately from our saved scene the path is where the script will be stored by default it will be named the same as your node in the scene panel this one is called Co cool cube. GD the GD extension tells gdau this is a GD script file you can store the script separately from the scene for instance you could put all your scenes in a folder and all your scripts in a different folder it doesn't matter to gdo everything looks good here so let's create the script by hitting the create button down at the bottom so we are now in the script editor we can exit or return here by using the menu up at the top we can also open or create scripts from here or we can close the side menu with the arrow there is also an option called No distraction view which can help us focus on just the code let's take a look at what we have the extends mesh instance 3D at the top has to do with the inherit property we looked at when creating the script it's just telling gdau that this script and node are going to be a mesh instance 3D the next thing we can see is a grade outline that says called when the node enters the scene tree for the first time this is a comment the hashtag at the beginning is telling the engine to ignore this line this line is only here to help us the user understand the code better it's not included into the code when the project is run the next part that says Funk underscore ready this is the start of a a function function in programming are like subsets of instructions we could imagine a washing machine as a program and there could be functions for rinse drain and spin whenever the washing machine needs to run its cycle it could just call the function spin rinse and then drain in whatever order until the process is complete when we want to use a function we call that function by invoking its name with parentheses so for our washing machine example a sample script would look like this the function run wash cycle calls other functions in the order we need this is the power of functions it saves us from rewriting the code multiple times going back to our script now this underscore ready function is also a special function within gdau because we don't need to call it anywhere as the comment said this function is called when the node enters the scene tree another way to say this is when the mesh instance 3D is created in the game World this function will run automatically the scene tree is the system in gdau that keeps track of all the nodes we are using when a node is created in the game world it is added to the scene tree so let's do the simplest thing we can we want to print out information on the scene from our script luckily we can just use the print function like this we type the word print with the parentheses and add our text inside the parentheses like this the next thing we need to do is add quotation marks around the text to tell the engine this isn't code this is just text so let's print the phrase hello world which is the traditional learning to code message after we have this line in our ready function let's try running the scene again and we can see the result we can close the scene after opening it and then let's view our output tab which should have our printed message hello world that's cool but not very useful let's instead print some information about our Cube let's use the print statement and say print position with no quotation marks this is telling do to get the position of the cube in the world and print the result let's hit the Run button and see the result the position is displayed in the output tab you can see the position is in the form of a vector 3 which is just the coordinate system for a 3D World the position is a property of our cool Cube we can view the properties in our inspector panel we can then use the names we find here to track or manipulate those properties of our object let's change the value of a property to see how it will affect the cube let's just type this line scale doxal 5 in the ready function if we run the scene we can see see the cube mesh is scaled five times as large on the x axis let's explore a little further what if I want to change the color of the mesh when I hover that property on the material it just shows up as albo color but that's not enough info for gdau to understand what we want instead we have to chain properties together with the dot operator to access those subproperties so we could do something like print mesh. material. albo color the value we get returned here is the color of the mesh in the rgba format we will go over this later in more detail but for now it's not super important just know we can access and influence properties of these nodes through code by identifying the property's name in the inspector so now that we know how to run our scene and how to print info out to the scene we should learn about variables in gdau if you don't know what a variable is it is simply a placeholder for Value if you know algebra x in the equation is the variable it stands for another number in coding a variable could hold numbers letters or even an entire level let's create a few variables and then we'll see how we use them we could do something like VAR my int equals 1 this gives us a number variable with a value of one we can call this type of variable in int or integer value variable we can create another variable my float and set it equal to 2.2 this variable is referred to as a float because it has a decimal value instead of being a whole number like an INT we can create a text variable referred to as a string by saying VAR my string equals and then here's a string with quotation marks which will create a text variable with the value of here's a string in each case the VAR is a keyword telling a do you are making a variable then the next part is the name of the variable the equal sign is assigning a value to that variable and then whatever is on the right side of the equal sign is the value being assigned common variables that we will use will be things like the health of the player the speed at which we run or the damage our gun does uh etc etc we will be using variables in just about every script variables are a huge part of programming so let's use a variable for a more useful purpose let's make a variable and move our Cube to that position if we look at our position in the game world we notice we have three coordinates X Y and Z the x is horizontal the Z is forward and backward and the Y is up and down in gdau when we printed our position we got this result and this is called a vector 3 really it's just the format gdau needs to understand where you want to go I'll demonstrate Now by creating a variable called my VC 3 and setting it equal to Vector 3 0 02 this will set the value of the variable to a vector 3 with the value of a zero on the X Z on the Y and a two on the Z axis we can then set our position equal to this variable to move to that position with our cube when we run the scene we can see the cube has updated its position computers are very o CD about how code is arranged the rules by which the code is arranged is known as syntax we can look at some general syntax in gdau to clarify notice the indentation of the lines of code that belong to the function this is the syntax of functions all code that belongs to it must be indented and underneath it another example of syntax at play is when we wrap the string variables in quotation marks to let gdau know not to interpret that part as code so while it may seem like pointless complication at first the objective is to be precise the point of syntax is that the computer doesn't have to guess at what you want it knows exactly what you are trying to do errors are caused when your code confuses the computer to a point where it cannot continue you may notice some lines turning red on the screen and some text appearing near the output tab this is an error and when it is due to incorrect syntax of your code we call it a syntax error this is stuff like forgetting a quotation mark or parentheses missing a colon or not indenting your line inside a function the engine will typically identify and try to tell you what it does not like if you can't figure it out from the message you get here you can Google the error and you can see how others have dealt with it online errors are misunderstandings on the computer's part that it cannot resolve by itself a game engine tries its hardest not to crash or throw errors but if we write code that it can't interpret the engine will crash and display an error it is nothing to worry about because this happens all the time getting an error in crashing your program is a natural part of coding and doesn't hurt your computer at all moving on to talk about the underscore process function the process fun function runs every frame in the game so this is used for things like getting input or movement because it is continuously running without us having to Loop it ourselves let's demonstrate with an example let's put the same print statement we did in the ready function into the process function too so we use the print command with parentheses and add a string inside the quotation marks to print out now we can run the program and see the result we can see the print statement executed a ton of times instead of just one so what's going on the underscore process function is another special function in gdau that runs every frame So when you say a game is running 60 FPS that means that the logic of the game is able to execute fast enough to load everything 60 times a second FPS frames per second so every frame the process function is just printing the statement we asked it to instead we want the game to check for input every frame input meaning is the player pressing a button that does something in the game going back to our process function we can see that it has an argument called Delta Delta is the amount of time between the frames and the process function we can actually print the Delta variable by using the print command like this print Delta let's run the scene and check the results we get a value of 0.0166 repeatedly printed out every phrase frame so every frame is taking about 0.016 seconds to run if we divide 60 by 1 we get this number this is because we are running at 60 frames per second if this sounds like useless information don't worry we will use it later programming and Concepts so to get you coding there will be many new Concepts to learn we have already seen a few of them like variables and covered rules like syntax there are a few more components we need to get going if you are new to all this information it is probably pretty overloading a lot of these Concepts usually take a few hours to understand and we are going through them every few minutes I made this guide because I learned all these things through separate videos which took years of time condensing everything into one space should help speed up the process that being said the next concept we need to cover our arguments and scope they go hand inand so we kind of teach them together to understand arguments first we have to understand a concept called scope scope is basically where variables are available in a script we will revisit our washing machine example to explore further a variable defined inside of a function is scope to the function other functions won't be able to use it because they don't know if it's existence if we make a variable in the wash function we won't be able to use it in the rinse function because the variable is outside of the rinse function's scope the rinse function has no idea what you are talking about we can create a variable on the outside of the function in What's called the global scope this variable will be available to all functions in the script but if we had a situation like this we have the Run wash cycle function which we will use to wash some clothes we Define the clothes as three string variables one named Socks one named shirt and one named shorts we want to access these variables inside the other functions but they are in global variables so their scope is limited to the Run wash cycle function one way we can fix this is to pass these variables in as arguments to our other functions we do this by placing the variable name inside the parentheses when we call the function we also need to tell our function received receiving the argument to expect something not warning our function of an incoming argument will actually cause a syntax error in the editor telling the function to expect an argument and then not sending one will also result in an error we can do this and send multiple variables as arguments as long as the numbers match up three expected three sent two expected two sent this is a basic basic explanation of arguments and scope we will certainly get more practice with both continuing with our goal of getting player input let's start really simple first we need to make a binary decision meaning a two option decision is the button pressed or is the button not pressed this is a good case for an if state statement and if statement will run if the condition given is true we can test it now if we go back to our ready function and try a couple out let's comment out the print statement in our process function to make our output a little clearer let's get back in the ready function so our code runs just once we can try an if statement by saying if 1 equals equals 1 colon print this is a true statement with a indented line underneath it let's take a look at the syntax of the print statement we have the if keyword which tells gdau to evaluate if the condition we are checking is true next we have the value one which is the first of the values we are comparing then we have the double equal signs this is to denote to G do that we want to check the values instead of setting 1 equal to 1 2 equal signs tells gdau I want you to look at these two things and tell me if they are equal one equal sign tells gdau to set the value of what is on the left to what is on the right finally the colon at the end is signaling the end of the if statement check and to start the logic of the if statement this is the part that runs if the statement is true Everything below that block should be intended to run when the statement is triggered back to the if statement we can also try if 1 equals equals 2 colon uh next line and then a tab print this would be an untrue statement we can then run our scene and see that only the first print statement ran because the second statement was not true so if something is true then do something getting a little less abstract let's say if the player presses the the button then move forward with that understanding the next part of the equation is the actual getting of the input the registering of the button press by gdau we need to use something called a Singleton a Singleton is basically a script that is always available for us to call that has functions we can use we can view the input Singleton by going to the help menu and typing in input if we click on the input Singleton we can see all the functions that we can use by calling it this is the one we want is action pressed we will check if the action or button is down or up let's type in our process function print input. is action pressed UI up we can then run the scene we should see a value of false occurring over and over again until we press the up arrow on the keyboard then we see the value say true so whenever we press press the button the function is action pressed is actually returning a true or false value depending on whether the button is pressed or not now The Following part was very dense with new ideas the approach this tutorial is going to take is to think of these ideas for their utility and not give tons of theory behind the scenes you may not know how a car works but you know how to drive the same Theory applies here you may not know exactly what an input Singleton is at the moment but you should understand that we can use the input. is action press to check a button press so let's combine the if statements assessment ability and the input signal Ton's return value to check for a button press this would look like this if input. is action press UI up colon print we are pressing that button now let's run the scene we can see now that every frame we have the up button pressed we display the printed statement if we apply this to moving we could move every frame the forward button is pressed let's do just that with the w and D keys do this by typing if input. is action pressed and then a w inside of the quotation marks and a colon at the end this time with the w key in the quotation marks meaning we are checking for an action named W for the block of the code to execute we will move down a l line and indent and then type this positionx equal positionx + 1 what this does is add one to the xais position of our Cube for every frame the W button is pressed by updating our position every frame we achieve continuous Movement we can simplify this line by changing the part where we update our position we can say position plus equals 1 when we combine the plus with the equal sign sign we tell gdau to take the value of the starting variable then add the number on the right to it and set the value equal to the new number it's just a shorter way of writing what we already wrote above we just need to do one more thing before we can run our scene we need to add the W input into the input menu in gdo we can do this by selecting the project settings at the top and clicking the project settings from dropdown after that we can select the input map tab here we add any actions to the game that we need let's type in w and press the add button this will result in the action being created we can then choose the plus button on the action to select which button will call this action we want the W key on the keyboard so press it and gdau will enter that button as its trigger you can name the actions whatever you want and sync them to any button but we will keep it simple for now let's make an A S and D actions and then add values to them accordingly as a side note when you call the input Singleton like we are doing here the action name is what you are entering as a string in between the parentheses as an argument so just make sure what you typed here matches what you typed here let's run the scene and see how our Cube responds when we press the W key our Cube shoots to the left our exposition of the cube is being added every frame we have the W button pressed it shoots offscreen too fast though let's add other directions and address the speed issue in our script to make the speed easy let's make a global variable at the top of the script called speed we will set it equal to 0.1 which will slow us down a bit now let's head down to the process function and add the other directions of movement we first have to fix the direction of the cubes movement right now we are moving to the right when we press the W key we should be moving forward instead so let's change the axis we are moving on from the X to the Z now we can add three more if statements with input checks to move the cube in all directions I'm going to copy and paste instead of wasting your time typing it all let's go through it real quick we basically just copy and paste but we also have to change a few values here and there first we have to adjust the action name to match the button we want to check we also change the axis we are moving on depending on the direction going One Direction on an axis is adding to our position while going the other direction on an axis is subtracting from our position I have it separated out a little to make it easier to read and understand let's run that scene and see what happens the cube should move in all four directions and diagonally if we press the two buttons now we are going to start creating our player this isn't as bad as it sounds gdau has many time-saving features that we will take advantage of we have an understanding of the ecosystem at this point we understand that the flow of the gdau engine is to create scenes with nodes in them and code the nodes to make the game playay actually work it seems simple enough if you are new and you have gotten here congratulations it takes a while to understand these things uh should be proud of where you've gotten we want to continue moving on by creating the player so we can walk around the game world that we created earlier in blender so let's create a new Scene by pressing the plus button in the Middle top of the main window when we have that scene Open click the Plus in the scene inspector to create the root node of that scene we want to create a character body 3D node so we search and create one with the menu let's rename the node to player and save the scene by pressing contrl s because we have never saved this scene before a menu will appear asking us where we want to save I will create a new folder called player and save the scene there we can view the docs page for this node by searching it in The Help menu the node is described as this a 3D physics body specialized for characters moved by script in simpler terms use this node for your player character we will be back to this page later but for now we need to return to the 3D Editor to complete the setup of our player if we hover over the little yellow warning triangle we get a message saying this the node has no shape and it can't Collide or interact with objects consider adding a collision shape 3D this means we have no shape in the game world we are just a formless character entity we need a shape to tell gdau how big we are and what we are bumping into in gdau anything that collides with each other in 3D will usually need a collision shaped 3D node let's add one using the scene inspector menu as a child of our character body 3D when we find the node and press create it is is added to our player scene let's go ahead and rename that node in the scene tab by double clicking it slowly I'll name the Collision shape 3D node as player Collision we still have a warning on the Collision shape with a triangle and when we hover it gdau relays this to us a shape must be provided making sure that our Collision shape is selected let's add a shape by clicking the shape drop- down in the inspector we will choose capsule mesh for our player shape in the 3D viewport we can see now we have the outline of a capsule shape let's move the position of our capsule shape so it is level with the ground grid just make sure our player will stand on the ground if we check the inspector of the capsule mesh we can see that the height of the capsule is two so setting the position to half of that on the Y AIS will mean the shape sits perfectly on the ground we may need to adjust the shape of our player later but for now don't worry too much if we were to run the scene right now we would get no errors but we would see nothing at all just a gray screen this is because there is no camera in the scene so gdau has no idea where or what to show we need to add a camera to our player so we have a viewport into the game World all of the interaction in a game is for the benefit of the user a computer would be perfect ly happy to display a blank screen all day without complaint so we want to add the camera but we have to add a node first to help the camera work properly so let's click the plus sign in the scene tab to add a new node and select the basic 3D node from the list after we have added that node let's click the add node button again and add the camera 3D node your scene structure should look like this your character body is the root your Collision shape and your node 3 are siblings and the camera is a child of the node 3D child nodes move with their parents so in a way our root node is just a placeholder for everything that is our player let's rename the node 3D holding our camera to camera holder this makes its function a little clearer we are making an FPS so let's move the camera up to the position where a head would be we don't actually want to move our camera though we want to move our camera holder node this may seem like needless complication but it'll make more sense later on we are now going to code our character I like to think of this as giving the character the ability to interact with the game World the first interaction we need of course is movement gdau has a template script made for character body 3D nodes that gives us FPS movement we will use the template script to get us going faster now we can add a script to our player to get him moving make sure our root player node is selected we can press the add script icon in the scene tab to open our script menu we don't have to change anything unless you want to alter the name gdau is starting us off with a run-of-the-mill FPS script for a character body 3D gdau offers templates like this for certain notes that are specific enough to Warrant it we can open the script and take a closer look with the script open we can see that at the top we have the extends keyword just like before and just like before following the extends keyword is the type of node we are using simple enough we don't really need to understand it it's just there and it's doing its thing we continue down and see some variables these variables are not being defined with the V keyword instead they are being created with the const keyword const is used to define a variable that should never change the speed and the jump velocity of the character shouldn't change so movement feels consistent we cannot assign a new value to a constant the engine won't let us it's a restrictive measure to save us from ourselves our character's speed should influence his movement and not actually change continuing down we have a VAR for gravity and it is equal to a single that is using a function to retrieve a value this is working in the same way as our input Singleton earlier that one checked for a button press value and returned it this one checks for a value we can change in the settings menu that affects the entire engine's gravity that is not needed we could just set it to like 10 or some other number so we are constantly pulled down just like real gravity but this is nice because now we fall at the same rate as other objects in the game and we don't even have to code it mov mov on to the meat of this script we see the physics process function this is the same as the process function except this one is better suited to handle physical objects in our game like people or cars or barrels or other things that might fall after that we see that we have an if statement the keyword not is used to reverse the check of the condition meaning only fire if this is not true the function is on floor is a function that is is available to us because we extend the character body 3D script If This Were a mesh instance node instead of a character body 3D node this function would not be available to us the function is on floor is built into the character body 3D nodes we can view this function's docs by checking the help page in the docs we pulled up earlier we could always retype it into the help menu but once you pull up the help page for a node it stays in your recent scripts menu if you are wondering how do I know what is available to me and for which node the help docs are your answer let's check the documentation for the is on floor method to demonstrate we can see that it checks the player character and to see if it's touching the floor this is what we needed the Collision shape for so the character has collision and can touch objects in this case the floor the indented line beneath the if statement is applying our gravity to the Y component of our character's velocity variable the velocity variable you won't find defined in a script with the VAR keyword instead it is built into the character body 3D script just like the is on floor function we can again view this variable in the documentation page but really it is what it says it is our player's velocity how fast is the player currently moving this is our velocity this is different from our speed which is how fast our character should be moving when we want to move here we are influencing the Y component of our velocity which is a vector 3 the Y component in gdau is up and down so it makes sense gravity would be applied here we are again using the minus equals operation here to shorten what we type the line beneath it that is commented out would do the same thing the gravity variable we discussed earlier is a number that is set in our project settings for convenience the multiplication by Delta is new to us as a a refresher the Delta variable is a number that stands for the amount of seconds past since the last frame update multiplying by Delta will move us at the rate of the physics process function this keeps us in sync with the physics of the game don't get too caught up in this for now we can just leave it as it is the next part of the code is allowing the player to jump the if statement is using the and keyword to check two conditions at once this means that only if both of these conditions are met will the code below function in this case the two conditions are that one the player press the space bar here called UI accept and the second is that the player is on floor we check if the player is on floor because we don't want to be able to jump up and up into the atmosphere we only want to be able to jump off the ground if we are on it just like in real life you can't just keep jumping to fly so once we know the character is on the ground and the player has pressed the jump button we apply the jump velocity constant to the velocity doy value pretty much applying the opposite of gravity why don't we have to multiply it by Delta or use the plus equals operator because of how gravity works when an object is falling it will get faster and faster until it is at terminal velocity we mimic this in gdau by adding velocity doy to itself in the gravity section so each frame the object is falling it is moving slightly faster when we jump we don't want this effect we just want to move up and then let gravity push us back down again we aren't gaining inertia the higher up we go we are overcoming gravity and then being overcome by its influence seconds later of course we don't really need to change anything so don't worry too much about any of this we won't really need to change too much here anyway moving down we have a variable called input dir this stands for input Direction This is the direction the player is pressing on the keyboard W for forward s for backward a for left and D for right is the standard we can see the value of input dur is actually the return value of a function that function is from our input Singleton we can view that function's docs to better understand what it does now is a good time to mention that we can open up the docs page on something by holding the control key and left clicking the keyword we want to explore once there we can hit the back button in the upper right hand corner to return to our previous script this is much faster than having to search it every single time if you haven't already opened that page it says that this function gets an input vector by specifying four actions for the positive and negative X and Y AIS basically it is going to take the four buttons we press w a s and D when one of the buttons is pressed it will take that into account and change the value of the vector 2 it is returning based on that button press we can put a print statement here to view the vector 2 we are getting back let's do that and run the scene we don't have this function set to our keys yet instead we have to use the error keys to see the change so when we press forward we return a vector of 01 if we hit backwards we will have a vector of 01 if we go to the right the D key our Vector is 1 0 if we go left our Vector is negative - 1 0 this is just a way for us to assign a number value to each key press that we can apply to our player's velocity so now we have the inut Direction which is the direction we want to go the next variable named Direction translates our input Direction into an actual direction for the character to move in think of it this way with just the button input we could move but if we were to rotate ourselves in the game world we would move in the wrong direction without accounting for the character's rotation W will always move us forward in the game world but it may be sideways for the player so in simple terms we just apply our character's rotation to the direction we want to go in this will give us FPS movement so here's a good example we have our character here and this red uh box is denoting where our character is facing so right now we're facing forward so we can imagine that if we're moving our character in the uh forward uh direction we're pressing the W key so we're moving forward and uh maybe we're pressing the a key and moving to the left or the D key moving to the right right that's all fine but the second we are rotating our character here so we rotate this uh let's say 90° so we're facing the other direction there and now if we hit the W key we're still going to move this way because we're not moving based off the character's rotation we're moving based off the world's orientation so if we press W we're going to keep moving this way even though the character is facing that direction and we really want to be moving that way so we have to adjust for that by multiplying by the basis of the character which is essentially just the rotation and scale put into a complicated math equation but we don't really have to with that all we really have to do is just uh multiply it so so how we do this is by applying our character's basis to the input Vector this will Orient our player's input with the player's current rotation the basis is is a subproperty of our transform property we can view our transform by clicking the player node and viewing the transform menu in the inspector the basis is not specifically listed here but it is the combination of the rotation and scale values found in this panel we can also view the documentation for basis by going to the help menu let's do that quickly just to have the page available if needed in our quick menu the math that makes this work is pretty complex the more you study it but the whole point of using using a game engine is that most of the hard tedious work is already done for you all we need to know for our level right now is that we apply our basis to our input direction to move our player according to his own rotation in the game world let's look at the rest of the line after the basis we are multiplying by a vector 3 the x and z components of that Vector 3 are from our input Direction variable we add a zero for the Y component because we don't want to influence that axis of movement with these buttons the Y would be up and down whereas the x and z are forward backward left and right we can't multiply a vector 2 by a vector 3 which is why we add that zero for the Y so we can multiply by our basis which is a vector 3 the normalized function added to the N is a function unique to vectors that is pretty mathematically complex for us it just means that our character will move at the same rate going forward and backwards as they will diagonally so if we press the left and up Keys our character would move faster without this function diagonally than it does normally going straight but with this function we fixed that so that's all we have to do is just add it to the end there let's keep moving there is no need to over complicate things for now we have the player input accounted for we know which direction we want to go now we just have to apply it to the player node looking at the next if statement we can see that it says if direction we know an if statement assesses whether something is true or false but how can a vector three be true or false well a zero to gdau and in most programming languages is interpreted as a false value so if we have a vector 3 with a zero value for each component then it's the same as having a zero so what this if statement is assessing is whether the player is pressing a movement button when the player presses a button our Direction changes is from a zero value to a nonzero value making it true and running the code in our statement so what does the code in our statement do well here we can finally set our velocity to the x and z components of our Direction Vector this moves us forward backward left and right in the game world we multiply that number by our player speed without this we would move really slow after the if statement we have an lse statement which runs in the condition we listed in our if statement is false in this case if the player is not pressing anything the if statement will be false and the lse statement code will run inversely when the player presses a button the if statement is now true and the else statement code will not run the L statement here just gently moves our velocity back to zero when we aren't pressing buttons we can view what the move toward function does by holding control and clicking on on it in this case it just slows our inertia to zero this will make the movement much smoother and less jumpy at the bottom we see the move and slide function this function is the call to gdau to update our player's position based on our velocity we have just learned a lot so let's leave it at that the only thing we need to change is the action buttons being used in the G Vector we need to replace the UI stuff with our actions w a s and D that we made earlier just make sure to put them in the right place left is a right is D up is w and down is s if you find yourself moving in the wrong directions check here we can do something fun now which is ready our blender scene to put our player in so if you remember from earlier in the tutorial we exported our blender file uh to gdau um our thing that we made and I'll show you I actually made some mistakes so we're going to have to re-export it um so let's jump in here where did I put it I think it's level a there we go so we can just drag that in and you can see if we click on let's uh we have to right click and say make local that way it's local to this scene and we can edit it and I just want to hide that so we can see we have this plane on the ground that I meant to extend to both sides and I mirrored it but I didn't apply the modifier and blender uh and I was just showing you that that's what it's going to look like the other half won't be there so if I uh maybe I can do this see over here it looks like I have the whole thing thing that's cuz I have the modifier still not applied so I'm going to go ahead and apply that so that way we get the entire shape there coming over this entire shape here so let's go ahead and do that I'm going to reexport this by saying uh file export gltf we've course got to go to I think test project yeah um we'll go to let's just make a new folder and say best dist levels and uh we'll go here and we're going to do better level go ahead and save we don't really have to change anything we can then go back to here we don't need this one anymore we'll just delete that rude node we can then uh go down and let's see where that folder is at uh bestest levels and then we'll drag that one in and let's just go to it real quick and turn the transform back to zero so now you can see uh well let's go ahead and make it local now we can see that uh if we drop that down our plane is the full shape so if you have shapes that aren't appearing or they're looking like they're Hollow or just kind of weird uh go back to blender and check your modifiers because your modifiers might be part of the issue so now that we have this we want to click on the plane here or whatever you want the character to be walking on or colliding with and we have to make a uh Collision shape so we come up here after we have it selected we go to mesh and we say create create tresh static body and you'll see these little blue lines appear uh might be hard for you to see them um because of where they are but uh they appear on the model you can kind of see them a little better over here if I bring this up there we go these little blue lines here so now now that I have this better level there what I'm going to do is click this little chain link which will you to instantiate a child scene and we want to instantiate our player so we click on the player and we have him here and we want to put him right in the center of our game world so we'll bring him up that way we're standing on the thing right there he's going to fall down a little bit and we can go ahead and run this but we have to save it as something so we'll save it as um best love level uh a so now using our w s and D Keys we can move around in this little game World however we cannot turn yet which is what we'll be implementing yet uh implementing next so stick around um and we'll be doing more stuff getting this going uh getting close to being actually fun now so we have our player and we can move up down left and right but we can't turn our character so we want to implement that now and to do that we have to take more player input and then take that input and influence it on the Node in this case we are going to turn our entire character in the Y AIS when our Mouse moves left and right and that will make our character move left and right accordingly let me go ahead and turn that back to Z zero we'll go back to the script and I'm going to paste these two functions in here and then we'll go over them so this ready function here we've already seen this function runs every time that the player enters the game scene well when the player enters the game scene it's only going to do it once but as soon as the player enters this function is ran the input. set Mouse mode what this does it uses the input Singleton and it captures the mouse so that the mouse can't move and the uh cursor is not seen if you think about Call of Duty or any other game you're not going to fly your mouse off the screen and then be clicking on other programs you don't want to be doing that you want it to be locked to the screen that's what this enables right here the next function we haven't seen before it's the input function and it takes in an event and the event is basically any key that's being pressed on your keyboard so if you press any key or you move your mouse or scroll the mouse that's registered as an event with gdau and so we're taking this if uh statement here and we're saying if the event is of the type input event Mouse motion meaning did we move our Mouse then we're going to rotate uh our character on the Y AIS like I said earlier to the relative movement of our X um axis of our Mouse so that means left and right on the mouse is rotating our character left and right in the game just like we would think about uh in an FPS Movement we are not yet accounting for going up and down but let's just go ahead and see how this works and this de to rad what it's saying is degrees to radians so we're taking the degree that we get here converting that to radians and then we are sending that to our rotate y function because rotate y needs um radians and not degrees and this just makes it more efficient so I think it's more efficient than doing it with all degrees but uh don't stress too much about that right now let's go ahead and save we'll go back to our level here and run it now we can see we can move and we can move left and right we have some graphical issues but we can address those a little bit later and uh let's go a head and fix the moving up and down we can also go ahead and add something that's going to make our life a little bit easier if we add in this line here if event. is action pressed UI cancel uh this is the escape button that means that we will quit so get tree. quit just quits the game that way when our Mouse is locked we don't have to worry about pressing the Windows key to get out of it or anything so we can Run the game now and as soon as we want to quit we just hit the Escape key and we're done with it so that's uh that's the best way to do it all right now that we have that done let's go ahead and add the up and down so we can look up and down uh for that we're actually not going to add anything to the player script we're going to create a new script on our camera holder and uh let's just go ahead and name it camera holder since this isn't a built-in name we can name it that and it won't give us any warnings so we'll create that and then we're actually going to take um this exact line right here and we can just contrl C copy it that's what moves us on the Y AIS for our player and instead what we're going to do is move ourselves on the x axis of our camera holder so we'll change that from X to Y and just for demonstration if we go to our player in the 3D and we look at our camera holder here this is what we're moving is our x axis of our camera holder and we don't want to actually move our camera we want to move the camera holder because it'll be easier to deal with so now if we go back to our level having added that into our script right here making sure to change the Y and the X respectively we can run the level and we should be able to look up and down left and right and move in all directions and we move with whatever direction we're looking at so that's good there are no limits to how far up or down we can look so we could look all the way around and make ourselves sick which I'm not going to do and if we fall off the edge here we slip into the abyss and fall forever because there's nothing to collide with down here but we can fix all that and we'll we keep going Let's uh keep doing fun stuff all right so our scene really looks like when we go into it so we're going to uh zazz it up a little bit so first thing we can do is grab our plane here and we really don't want this to be seen so we can actually grab the static body and just pull that out of here I believe and hit that is that error saying nonuniform scale oh I guess we didn't apply the scale so if I go back to my blender file here and I look at the scaling for this object we can see the scale is actually not All Uniform which uh normally isn't a problem if you're just doing meshes that are just going to be somewhere but if you're doing meshes that are going to have um Collision based off them collision and scaling doesn't really work so well in Gough so you want to make sure that this is scaled all to the uh one um not all to the one but it's all scaled normally so I just got to click on that I got to go contrl a and then we'll apply the scale the uh the other ones here the location and rotation you can leave those where they are that's completely fine uh let's just grab everything in the scene by doing control a we're going to go uh yeah we'll just hit a and then contr a and then scale so now everything uh has been scaled so we can file export gltf and we're actually going to go to the documents um where is it at uh test project um bestest level and we're just going to save right over top of it and then we're going to go back to gadeau and we'll probably have to just take this and delete it and then we'll just drag it back in uh yeah right here we'll go here and set it transform to zero and then we will make it local and now now if we say mesh create TR mesh static body we don't get an error there we can pull that out and then we can just hide that because there's really no reason for it to be there so now if we run the scene we sit on the actual ground and uh you can see the textures don't look so great um well we're going to fix that one thing we can do to fix that is if we click on some of these right here uh yeah we'll click on this we can adjust the textures here so we'll come down and I am going to activate tripler we'll see how that looks so that's what that does and we can adjust the scale so if you want this type of look you can go like 0.0 2 I think that would look pretty good we don't have to use tripler we can still just adjust here by clicking and dragging but I'm going to go ahead and use it because I think it look a little bit better keep it right about there if I run that that's looking a little better another thing we could do is go to our player um uh this really doesn't have to be done but we can take our camera holder and move it up to about there I think that's about the height the player should be we're going to go to our player collision and we'll click that so we can get a good xaxis reference and then we're just going to go there and move our character right on up we're just adjusting our capsule shape and then bringing our capsule up so that looks pretty good right there uh we're going to save that now if we go back to our level we should be sitting a little bit higher off the ground and that feels a little more normal to me so the next thing we can do is um adjust these again go into the material and you can really change whatever you want here I mean you could uh change your texture if you want you can adjust the color if you wanted to you can make it more bluish or whatever but um for now I'm just going to adjust the UV maybe adjust the scale a little bit and I think uh right about there looks a little more reasonable let's just put it at three so I'll probably go around and do that for uh most of these objects if you were a real artist and you were like super into UV editing and all that stuff you could do a better job of this I really don't enjoy it so I just kind of take an approach to just get it done um I think that looks pretty decent uh let's have a walk around this scene now it's looking a little better we do need to add something and that is the world environment so if we go to the add node uh menu and we add World environment this is what actually gives us all of our shading we click on environments we say new and then we have to fill this out a little bit we have a clear color background which is not what we want we want a uh I think we want a sky then we select our Sky we can say new sky and this is basically how gdau works you just have to keep on filling out all this until it's got all the stuff that it needs so we can do uh let's do new Panorama and then we can add a panorama in here and I believe I actually made a panorama somewhere yeah we're going to try this we'll drag in that Starfield there we go all right so now we have a sky background we can make that a little bit larger and we can come down here and add different type of effects and light so we can minus or uh subtract or add to the sky contribution or the energy of our sun so let's jump back in now and see what it looks like very dark as we can see there's not a lot of energy to things so we can go here and add a light and we have different types of light we have uh directional which is like a sun omni light is like a candle or a light bulb and then Spotlight is like a spotlight so let's do uh a sun type light and we'll go on this view here actually let not it's kind of vomit inducing uh let's go here and we'll bring this up and we'll spin it we just want to spin it that way so that the light is kind of tilted down and we want to tilt the light a little bit like that give us a little more I don't know Ambience or whatever and we can also color the light or we can darken it uh we can give it like a nice nice reddish or like a nice uh kind of yellowish hint so um yeah we can also apply more energy to it or less than the energy we're giving so that's one light and let's go ahead and add another light this will be a omni light and we'll make that bigger bring it up and then put it over here in this room so that the room is illuminated and this is the radius of the light we can go over here and change the radius over here too so let's go ahead and just give that a try so there we go we can see in the game World a little more clearly still not looking amazing we still have a lot of stuff to adjust but it's getting there so let's arm our character I'll show a time lapse of me creating a shotgun in blender I created a Mac 10 and a Glock pistol as well that we will put on the wall for the player to purchase we may make more items but for now this will demonstrate enough we are going to equip the shotgun to our player first we will use a node 3D to create a weapon holder similar to what we did with our camera holder this just makes it easier for when we change weapons later we will have a holder to parent the weapons too we make the weapon holder node a child of our camera holder node so that the gun looks where we look with our camera we then drag and drop our shotgun glb into the scene once in the scene we will right click on the Node in the inspector and then select make local we will then right click click on the Node again and select Save branch as scene this creates a scene just for our shotgun we can now instance our shotgun on our player when we need it let's add some animation to our shotgun we need four animations pump fire reload and misfire in gdau we use the animation player nodes to animate things let's add one to the shotgun scene now we can click on the Node and then open the animation menu at the bottom if it isn't already open we can then click the animation button to create a new animation we then add tracks to influence the properties of the node we can animate just about any property and even call functions through animations we're going to do now is just pump The Shotgun by moving the pump and rotating the shotgun up slightly we will then add sound to the animation after that so to use animations we create tracks let's add a track now and have it act on the pump of the shotgun the tracks hold key frames which are just marks telling the track where the object should be at that time we can demonstrate that here by selecting a key frame and changing its value on the right let's create a key frame for the starting position of the handle after that we duplicate and drag it to the end of the animation now let's add a new one in the middle and move the the handle back slightly on the Z axis now we can press the repeat on button to the side and play the animation to see the result it looks okay but let's add a tilt to the gun when cocked to make it a little more realistic so we add track and then select the shotgun node at the top to select its rotation property we do the same key frame setup to affect our guns's rotation and this looks a little better when we play it back let's duplicate this animation by clicking the animation button and selecting the duplicate option name this one fire and remove the movement of the pump to leave just the rotation we then move the middle key frame further towards the front of the timeline making the gun jerk more when fired the reload animation is a little trickier because we have a shell to move around as well we use the same track method to rotate the shotgun up ready for the shell we then have a shell come up from the bottom of the screen and go into the gun we then lower the gun we are also using a visible track to toggle the visibility on and off for the shotgun shell I'm not really going to go all out on these animations we will animate our enemies in blender but understanding the animation system in gdau is important as well let's add a blast for our shotgun next we will use a new node called the GPU particles node this is used for stuff like smoke or fire or a scattershot a particle system is a node in gdau that spawns a bunch of something in a pattern add a GPU particles node into the scene and navigate to the inspector options we are first looking for the draw passes draw passes are the thing that we are spawning copies of we can do flat planes or objects created in blender here we are going to use spheres as our mesh just like a shotgun shot we can edit the shape of the mesh as well so let's make it 0.05 here and uh 0 .1 on the height to make them BB sized then I will decrease the amount of radial segments in rings we do this because we didn't really need High defition geometry for fast moving pellets they're just an indicator of where we are shooting this saves the computer having to process more geometry this isn't significant enough to really affect anything but it's good practice to always try to do less with more here is where we set our materials as well Well for now let's just create a new material and set the vertex color attribute to use as albo this allows us to control the color of the material through our particles node after we have this set let's move to the processed material this tells gdau how to move and distribute the particles this field will be empty so we can click and create a new particle processed material now we have a bunch of fields to alter how our particle move we want a scatter shot effect first so let's change the gravity to zero then we can set the initial velocity to 30 for both the minimum and the maximum our particles are now flying all over we can narrow the spread by going to the direction and changing the spread there we will set it to five let's go up to time now and set the explosiveness to one this will create a blast effect now we can edit the color of the particles we could either choose to pick the color attribute or we choose to select the color ramp which allows us to change the color of the ramp over time I'm going to create a yellow to red white transition on the particles we could do a lot here but I'm just going for something basic let's take the particle system and rotate it to be at the mouth of the barrel to be clear these are just going to be for show they do not actually collide with than anything in the game World these particles are a visual indicator to the player of where he is shooting we are now going to add Ray cast to the gun so that it can hit targets let's click the add node and add a node 3D to our shotgun we will name this one Ray holder we will then position this to the mouth of the barrel as well we will then add a raycast node as a child of the holder a raycast is basically a long straight line that checks for Collision we will shoot eight Rays for the eight pellets and try to match the spread of our particles this makes it match up with what the player sees and what the Collision actually is let's change the orientation of our Ray cast to extend -20 in the Z Direction I think that is a good range for the shotgun we can then rotate the raycast around to match the spread of our particle it doesn't have to be precise just make it close this is a very simplistic approach but it's easy to understand let's repeat this seven more times with Ray cast to get eight Rays with them all spread out we can see how an enemy up close will be hit more times than an enemy far away you could make the spread larger or smaller by adjusting both the particles and raycasts but I like the way it is here now we just need to add the sounds to the shotgun to do this we need to add an audio stream player node we want the gray one at the bottom not the 2D or the 3D which are louder based on proximity adding it to the scene we can call it fire sound I have Reed audio clips that I got from opengameart.org we can drag and drop the sound clip directly into the audio stream player we will make three more audio stream player nodes for the other sounds the shotgun makes and name them appropriately we will also add the sound Clips to them now we have all the parts of the shotgun ready to go we just need to write the script to give the shotgun functionality all right so I'm going to demonstrate the shotgun script uh that I built and then I'll go over it so we have six rounds in our inventory right now and we have three in the chamber so once we expend those three we have to reload and then we can fire three more and then we can reload and then after these three if we press the reload button we get a misfire sound and once we fire our last round here we get a misfire so all the parts of the shotgun we need are there and uh yeah I'll just jump into the code now so the variables up here we will talk about as we see them in the script first let's look at the process function what we are doing here is first checking if our gun is the active gun for our character right now it doesn't matter because we only have one gun however we will need this when we start switching weapons the next statements should look familiar these if statements are getting the player input in this case if the player is pressing the reload or fire button let's run through the logic of these statements the first statement is checking if we are pressing reload if we are next we check the canf fire variable defined at the top of our script we use this variable to guard against the player spamming the fire button without this variable we could just fire over and over again without pumping the gun by setting this to false when we shoot or reload it stops us from restarting the reload or the shot we are currently taking so in other words what this statement asks is are we currently reloading or firing if so you can't fire or reload right now if we are free to reload we then go to the reload function here we first set the canf fire variable as discussed then we get how many rounds we need to fill the gun we subtract the max rounds the gun can hold which is three from the current amount of ammo in the gun so if we have one round in the gun our variable should be two because we need two rounds to fill the gun up the if statement then asks if the ammo in the player's inventory is enough to cover the rounds we need to put in if we have enough in the inventory we just subtract the rounds from the inventory and add them to the ammo in the gun however if we have less than enough to fill the gun we move on to another check here we check if we have any rounds at all if we have more than zero we put in all we have and clear the inventory if we have no rounds at all our gun calls the misfire sound to play we then set the canf fire variable to true so we can attempt to fire again or reload when we get ammo the return keyword tells gdau to exit the function there and stop running it so the code beneath this return is never ran if that branch is taken in all the cases but the no ammo at all return case we play the animation which is why it's here here at the bottom so after the reload input check we have the fire input check we do the canf fire check and then we make sure that there AR actually rounds in the gun if the gun is unloaded we force a Reload if we have some rounds in the gun we move to the fire function in the fire function we set the canf fire to false we also set off a burst from our GPU particles node by setting the emitting value to true the next line is subtracting one from the ammo in our gun the print statements just help us to keep track but are not needed the next lines play the sound and animations that we set up earlier the animation player needs a name for the animation whereas the audio node does not need that argument the last part of the script is the long named function down here this is actually a signal function this function alerts us when an animation finishes on the anim anation player node we are going to use this to Reco or reset our shotgun for example we shoot and play the fire animation when the animation finishes the animation node will emit a signal telling the script what animation just finished playing this is the argument we see in the function so we can then set up logic based on the animation we are coming from if we just fired we need to pump the gun if we just pump the gun we need to enable firing through the canf fire variable this is called an animation driven approach we do need to change a couple things on our particles to get them to work correctly we need to take the lifetime down to 0.9 when we fire we shoot particles then we pump our gun our pumping animation is 1 second and we need to wait for the particles that are on the screen to die before spawning more so we need to make the pumping animation slightly longer than our lifetime of the particles so we set our particles to 0.9 and our pumping animation to 1 second and we should be all good this is a shitty fix but it's a quick fix for now just to explain a little more about signals we can see that there is a signal coming from this node over here uh it says node has one connection if we click on the Node and then we go to the signals tab over here we can actually see all the connections it has we can even disconnect them and then we can actually reconnect them as well we just connect and then we know we want to influence the shotgun script right here so we press connect and it will automatically generate this for you in here I'll demonstrate it real quick so this will signal whenever the animation is changed and I can connect it to our shotgun node if I hit connect here it actually creates creates the script for us down here now we don't really need this so I'm going to go ahead and get rid of it and then disconnect it up here but just know that is how we made this script and this signal right there we'll use signals more uh but this is a very brief introduction and they're very useful in gdau so another important concept to address would be return statements and I kind of glossed over them a little bit but let's take a better look at them so I have this ready function right here and we're creating a variable called X and then we're actually setting that variable equal to the return value of this function here and we're passing in the variable five to the return number so our number number goes in here and all we do is return it back so if I run this now we get the number five because we're printing it out right after the function has ran and so what the return number does is it ceases the functions running and then Returns the number immediately back here back to whatever line called it so this line six right here so this print right here is never actually ran because it's underneath the return so this is never going to print if it's under the return statement if we move it instead to be up here we can see that it runs but uh anything underneath the return will never run in the function so moving it back down here it'll never run now usually in the function there'll be some type of logic here uh so it'll be like num plus equals 10 so we're changing this number and then then returning it and then setting it equal to a value that's normally why you would be using this in the first place but it's very important to understand how the return keyword works we can now go back to our shotgun script and here we need to add a collision check for all of our Ray casts we could do this one by one but now is a good chance to introduce four Loops into the equation four Loops will Loop for a specific amount of times the format of the for Loop is as follows for blank in blank and then the logic goes below just like an if statement let's look at the example script I have here the i in the for Loop is a variable scoped just to the for Loop we are actually declaring it in the for Loop right there its value updates with the current Loop when we Loop to five we get the values 0 through four printed to the screen that's because computers start their count from zero and it Loops five times we can name the I whatever we want I'll change it to my num and it has the same effect you may see I used often in a for Loop context used to mean increment it's just a short hand for a longer word the key word to learn here is iteration this is the act of looping through an object if we look at the Loop below we can say that we iterate through the value of the variable X both Loops print identically the loop below that is iterating through a string variable with the value Strang it prints out the letters individually we can iterate through more complex things as well it is a good time to introduce the concept of lists a list is a collection of values saved as a variable we can create a list by using the syntax seen here the list holds four values we denote a list by placing brackets on each side of the value after the equal sign this informs gdau that this will be a list and not just a single variable to separate the values inside the list we use a comma between the values when we iterate through the list we print all the values lists are extremely useful when looping looping and lists go hand in hand let's see the final last Loop of this script to understand a little more here we are looping through the children of the node holder and printing them to the screen when we use that function get children it means that we are are getting the children of that node in a list and then we Loop through that list using the for Loop we are going to do this for our raycast nodes and check for collisions instead of doing this Al to them individually so back to our shotgun script now all we've done is add this for Loop into our fire function and what this for Loop does right here is it is looping through the ray cast that we have coming out of the end of our shot gun here we're then going to check each one uh for what they're colliding with that way we can tell if we have hit something when we fired so going back to the script we can say for Ray holder for Ray and rayh holder. children which returns a list of all the children of this Ray holder node which is our Ray cast we then check if the individual Ray is colliding with anything if it is then we're going to print the collider if it isn't then we're just not going to print anything so now we can run this and shoot the ground and see if our raycast hit the ground but another thing we can do to make it a little clearer is go up here and click the visible Collision shapes to on it'll normally be off we click it on we can then run the scene sorry let's run the best level scene and we see our Ray casts that turn red when we are hitting something so if we fire we can see down there let me bring this up I don't know if I can but we could see at the bottom these are what we're hitting the static body we're hitting the floor so that would be this static body right here that we were just shooting so for every Ray that is colliding with the static body when we press the trigger we're going to get a print out here so what I'm going to do just to demonstrate is to aim at the side here and we'll only get like one print out because we only have one Collision maybe even less than that we can see we have a few collisions and then if I aim right in the middle all of them Collide so it might be easier to see if we go and shoot something like this we only had a few collisions see some of them only show up a few times and then and when we aimed directly at the ground we had all eight raycast hit so that's a pretty decent shotgun in my opinion so now we need to make an enemy and we're going to make something similar to this I'm going to go ahead and delete him we need to add and we're going to add a UV sphere we're then going to do is Click over here into the sculpt mode once we are in the sculpt mode we want to turn on on this dinoo which will allow us to make more geometry as we sculpt let me just quickly turn it off for now and you can see what happens see all those weird lines we're getting uh and it makes things difficult to sculpt we control Z all that and we go back to dinoo when we move stuff around on our uh object it actually adds more geometry to it so if if we grab like this and pull it out you can see it adds more geometry as it goes and this is how we can sculpt things in blender so we're going to contrl Z all that and then we're going to go here and uh I'm going to make a monster similar to what you just saw so what I'm going to do is first kind of flatten our Cube here I'm also using the snake hook tool that's my favorite tool I pretty much use that for everything I don't really do a whole lot of modeling though we're just going to make it look pretty decent so now that we have that mouth formation kind of made let's grab some of the kind of lip here and we're going to make like four almost like a a head crab from uh what do you call it halflife I guess they're like tendril hooks but also for the mouth you know what uh should we do three yeah I think we're just going to do three this time I think that's kind of cool so we got one there uh let's undo that let's turn this radius down let's do one there and then we're going to bring this one out a little bit kind of contrl Z let's bring that out like that so uh we're actually I think that will be fine and what we need to do now is uh we turn it down maybe like to 50s somewhere in there we can pull some of these little strands off can uh make an indent for the eye we can make the indent for the eye over here too doesn't have to be perfect we're just getting a rough estimate for now all right so now we can go back to object mode I'm going to go shade smooth so we have this sort of shapee here and uh let's add some eyeballs so we'll go add mesh uh UV sphere and I'm going to rotate so that looks all right let's go monster save blender file and then what we can do is grab add uh let's add a cube we're going to make that really small we're going to bring it up just so we can edit it a little bit easier and what I'm going to do is take it and just make it into a tooth so we'll say e bring that up kind of move that in and we look at it from the side we can spin it a little bit and then uh rotate it bring it back and do the same and then uh rotate a little more scale it um maybe rotate just a little more we'll do the same thing and now we have this kind of like Fang thing so we have that and we're going to say object uh shade smooth and we could could make this more detailed but I think that should be okay for now we're also going to take the bottom and bring it out and then bring that in and bring that out and then bring that in that makes it look a little more three-dimensional we can also do this and then scale that just a little bit and then put another one here and if we scale that a little bit it gives us uh kind of a weird but nice shape like that so we can then kind of spin this around and uh it's a tooth oh sorry spun it the wrong way r on the Z let's go 90 negative uh yeah bring it down so we're going to scale it and then we can kind of add these in and I'm just pressing shift d i mean there's more efficient ways to do this you could like create a uh what do you call it like a curve and then put them all along the curve but uh I mean this is like the fastest way to just slam them in there all right so we have our character here we want to animate them so what we're going to do is add some bones so let's go to add we'll go to Armature single bone We'll add that in we then need to come over here go to viewport display and click in front so it displays in it displays in front of our model uh the next thing we need to do is go switch into the edit mode and that allows us to edit uh bones here so we are going to take this one and move it kind of more towards the back and center of our model make it a little bit bigger this is the center bone for our model which will control its main Movement we are then going to add a single bone to that we're going to grab this one and these are going to control the mouth so we'll grab this and bring it over here we'll do is then grab this one here and grab the single main bone and we'll hit contrl P I think we have to grab it here and here and H contrl P and then keep off offset so what that does is make these two linked that when this big one moves it moves this one as well however this one is still going to stay this distance away they don't have to be connected so we can then move that right over here and we'll move this inward sorry I just meant to grab that tip move that in here and then move that right there and then all right we just need to do that a few more times I think we can just uh shift d and copy this so that's cool and then what we need to do is once we have that done let's press a on everything and hit contrl a and apply the rotation and scale of every object on our scene that will save us from running in issues later we are then going to click on our mesh and then click on our Armature and say contrl p with automatic weights we'll do the same thing with uh the eyeball contrl p and then the teeth as well select the mesh select the bone and print contrl p with automatic weights and what this does is it will do its best to map the mesh to the Bone so now if I move the bone around you can see that the mesh moves with it and we have these here as well we can move that and uh it's not you know it's not perfect but it does a pretty good job for this little indie project we're doing so what we're going to do now is start creating animations for our guy and we might have to adjust how the bones influence things let's actually go through and name these bones real quick so I like to name this one base uh we'll name this uh right top uh we'll name this one left top and this one's just the bottom middle so there we go and then we're not going to name these that would take too much effort um but we can go here into object mode and if we click on the mesh or we click on these uh eyeballs here which is just another mesh we can then go to the uh weight paint option and we can see how how much of the influence each bone has on it so right now we're on the base bone and we can see there's some influence because it's green if there's no influence it's all blue and then there's a lot of influence it's red so let's actually hide our U model there and then we're going to paint all the influence to our base so as you can see it's we have we're on the draw we can also subtract so we could uh subtract influence but we're on the bone we want we want all the influence to be from the base so let's go back to the ad and we can do that and we can move around and paint the entire eye so that the entire eye moves only with the base we can then go through these and go to subtract and remove all influence from the base and a faster way to paint the entire thing would be to uh if you hold alt and then go up or down it will start moving across the entire thing in a gradient the entire object in a gradient so that is alt and then pull in a Direction so right now I can alt pull and that removes all the influence move back to add alt pull and we have all the influence back on our base bone which is what we want so let's return now and hit alt H to unhide everything thing so now uh if we do move this bone back here pretty much everything moves with it and that is what we want so that if we rotate this model then we can rotate these two to make it look like it's biting or whatever so that's good uh what we're going to do now is uh let's save and we're going to go to the animation um tab in blender and if you've never been here before it's a fun place we have our 3D viewport off to the left we have another one off to the right and most likely when you come in you're going to be in the dope sheet but I like to move it to the action editor from here we can start adding new actions so let's put a rest pose in let's just do rest and we'll have maybe the mouth be a little more closed so let to take a top view and uh kind of push the lips or tentacles or whatever the you want to call them in a little more like that and we'll hit a and then we'll say I to insert location and rotation so that creates a key frame like the one we saw in gdau and then we're going to maybe move like uh I don't know uh five frames or so and we'll just kind of flex these out a little bit actually you know let's move like 15 frames and then we're going to go back and just Flex them a little bit so it looks like he's kind of breathing in and out and maybe kind of move this on the z a little bit and then we'll hit a and then we'll insert location rotation we're hitting a to select all the bones so we don't have to individually create key frames for all of them we only key frame what's selected so if I hit I here and uh location rotation it's only that bone and then if I hit a you'll see there's no other little dots showing up for the other bones so oops contrl Z and then we can also come down here and delete stuff or we can scale stuff or move stuff with these little dots so let's uh do that um we need to expand how long this animation goes on for and since it's going to be moving in and out let's actually take this and we're going to go shift d and move it around here and then we're going to take this one and then shift d and move it around there and then what we're going to do this time is come over we going to scrub to there and we normally pivot a little bit to the left but on this one we're going to pivot to the right instead and say insert location rotation and then we'll grab the first starting ones here and we'll put them uh down there and let's just have all this spread out we'll make it every 20 frames make everything even and we'll see how that looks for a resting pose so uh yeah we can click this button to get rid of all the blend stuff so now let's just run it we need to go back to let me put that in and we'll select everything we need to go back to about 80 so that would be how it would look at rest and uh I don't know I guess it's okay who really who really cares you know we just need to know what it is it's not this isn't a AAA game um next we're going to have a hit uh like a damage so let's do like take hit and uh we have some interesting things happening here which we can just go ahead and fix um let me make this key frame insert location rotation so um our mesh is kind of messing up and it's not going with our eyeball and what's happening is this part of the mesh is actually being pulled by these bones over here when we don't want them to have that much influence on that part of the mesh same with up here so let's adjust that by going back to object mode and then we'll hit weight paint and we can actually click uh through the bones to C so the bottom middle has influence all over here and we don't want that so we're going to go to subtract and just kind of get rid of that influence and that should be enough um let's see the that bone is have any the right top has a lot of influence right there so I'm sure if we start fixing this then you start seeing that it comes up a little bit more like what we want we do want some effect but very minimal right in that area so let's just go ahead and fix that up here too so that's kind of a little more with it and we never fix this eye so let's um go back to object mode click on that I we'll go to Weight paint again and we'll go to the base bone and ALT and uh go to add alt and then drag it back make sure the entire thing is red and then we'll go to the other bones click on the subtract and we'll go through them and then we'll go alt and pull the other way to make sure they have no influence so now that's looking better ahead and file export gltf we're going to go to our test folder and we'll make a new folder and call this one um monster go in here and Export it then we can go back into gdau uh let's go 3D scene let's go to our monster bring him in and see what he looks like so he's purple which is fine uh we'll make that local we'll then uh I think that should be fine I just want to see the animations okay yeah I can't I can't edit them until I save the scene but um they're all here I just wanted to make sure of that cool and then take hit we might actually use that as a spit animation and then we might just use uh because I forgot to make that but anyway we got our monster um we're going to start coding him so after we have completed the blender part we need to create an enemy scene let's make a new scene our first node to add will be a character body 3D node the same type of node we use for our player since we have a character body we need a collision shape we are going to use the capsule shape again create the capsule shape and leave the parameters where they are let's add the glb to the scene we can drag and drop and then right click and choose the make local option this places our GB in the scene normally the transform will be off zero so we can move that back to the zero position let's go to the animation editor if you haven't already saved the scene do so now I'm going to call M monster guy if we try to Loop or edit the animations we get an error that says can't change Loop mode on animation embed in another scene to fix this we just need to close the scene and reopen it again I'm not sure why this works but it does we don't need to close gdau just that scene now when we reopen it we can alter the animations let's Loop the bite animation and set it to auto start the auto start icon is in the animation player near the top we can only have one auto start animation active on the animation player at a time going back back to our main scene we are going to link our monster scene using the chain icon near the top menu once our monster is in the scene we can run and take a look our monster will float but we are going to use the character body being planted on the ground this way we can coat it like a regular walking person and then add a simple animation in gdau to make it look like it's flying and bobbing so we now have to code behavior for our enemy here and basically what we're going to do is have our enemy react to the behavior of our player so we're going to create separate states for our enemy to be in and then when the player triggers one of those States we're going to move to it that's a little abstract what I mean by that is uh we'll have our guy here in the rest animation he'll be resting and all of all of his code will'll just say just hang out here and then we'll have an area around him and when our player crosses into that that area he won't be in the rest State anymore he will move into the chase state so we'll probably play uh we'll have to make another animation for him to bob up and down but he'll be chasing the player in that state and then when he gets close enough to the player he will move into the bite state so that way he will just go ahead and bite the player when he's close enough and then he'll return to the um Idol state after he's bitten the player if the player is not dead he will return turn to chasing and biting him so it's all about separating out our logic so they're not all kind of hitting each other at the same time we don't want all of our code in the same place because then we're going to be running when we should be biting or chasing when we should be resting we want it all in different functions and what that looks like script wise is something like this where we have a physics process right here which is just a process function and we looked at that earlier that's running 60 times a second don't worry too much about this right now just look at this this is the current state of our our monster whatever our monster in this is just pseudo code none of this actually works but it's just demonstrating a point but we have our current state we set it equal to idle and then if it's in that state we only run the idle code right here which prints out we are idle and it checks for a button press when that button is pressed we then move to the chase state so then we will move on to this function down here and this code is no longer running and this code is now running so we've separated the logic out for these two functions which is the whole point of what we're trying to do so now that we are chasing we could uh say if we get too close to the player then bite then move to the bite function so let not what this is is but we could put all of our movement code here and have that lead into another function and then that's basically how it's done is we have all of this separated out into different functions here that we're going to run through and one thing we need to update is when we make RS we're not going to use an if statement we're going to use something called a match statement and what that is is I can say match current state and then put our uh I think it's what are those parentheses colons whatever the they are and then put that in tab over and we can do that here uh we just need to put idle Chase and bite oh sorry these need to come over they all need to be indented correctly so now we just say current state if it's equal to idle we do the idle if it's equal to chase we go to the chase code if it's equal to bite we do the bite code and uh the way we're updating it is we have these three variables right here we have current state next state and previous state and since this runs at 60 frames a second we take whatever the previous state is and we set it to the current state so we just saved whatever state we were currently in we then take the current state and set it equal to the next state so now we've updated whatever state we are in and then whatever current state we are in whatever updated one we're in we go and move into that code and so when we want to change States we change our next state and when we hit the next tick of our physics process it changes it for us in here and then we we move to that function so this is a big part of making character controllers and enemies is programming a state machine like this this is about the simplest one you can make that's useful you can complicate this as much as you want but I prefer to just keep it as simple as I can so we're going to start coding our guy now and for that we're going to need a script and what we're going to do is first create an area 3D around our guy uh around our monster so that when the player walks into it the monster then knows to change to the other state which is bite so we're not going to worry about them facing the player or actually being synced up and moving towards the player right now we're just going to switch two states it'll be idle and bite so let's create our script here and we're going to get rid of all this stuff right here and I'm going to go back to my example script that I made and and copy and paste some code so I want to grab we're going to need States again we're pretty much going to need all of this so I'm going to contrl C and then I'll go back to my monster guy script and we'll get rid of you we'll paste that in so let's get rid of the chase because we're not going to be chasing and then let's create a idle and a bite funk idle pass funk by pass so now all we're doing is creating our states and then updating our states uh but we don't have any code so it's just going to stay in the idle State and do absolutely nothing so let's add a node to our monster that uh goes around him and checks if the player is near and that's going to be an area 3D so an area 3D is just an area that checks for if anything collides with it we add we need to add a collision shape just like just like our monster it needs a collision shape to exist in the world so we'll click on this Collision shape down here and we're going to make this just a uh might as well make it a box make it simple so what we're going to do is detect our player if our player enters this box area then we will change to the bite state so what we need to do is go here go to our node and we say area entered and uh body entered is actually going to be the one we want because our character is a body this uh character body 3D is considered a body so we're going to go to area 3D body entered we're going to say connect connect it to our monster guy and then that creates a function for us this is a signal and this body right here is the body that is touching our box so whatever touches our box is going to be given to us in the script here so we're going to check if what we're touching is the player by saying if body. is in group and then we can put in quotation marks here because it's a string player and so then if it is a player we want to execute some logic and that logic will be to say next state equals and uh we'll change that to bite all right so we just need to we change that to bite and we are updating our state to bite whenever we bump into the player so we actually need to go back to our player here and change the uh groups we need to add a group so we just come over here and type player and then we hit add and this little box shows up over here on our player node and then we can see that we are in the player group so now we can be detected by this if statement right here when our body our player bumps into us as the monster so let's add a little bit of uh functionality to these codes so we're in idle and all we want to do is simply play the idle animation so we'll do our dollar sign for get node and then we'll say animation player and that is on our monster node so we can hit enter and then we'll say play and we just want to play play the rest animation and then we can do the same thing here we'll contrl C and then we'll go to bite contrl + V and we'll press well we'll put in bite there so if we're in the idle we're going to be playing the idle animation and we're in the bite we're going to be playing the bite animation and the frame is being updated every frame and so let's go ahead and update uh let's add another signal on our area 3 D so when our body exits we go back to idle so we click on our area 3D sorry make sure it's selected then we go to signals and we say body exited so whenever something exits our area 3D it will contact us through the script here and we're going to take this line contrl C and then uh put it down here oh my gosh work with me uh right there and instead of saying bite we're going to say idle so let's give that a shot I believe we already put our monster into this scene uh if not let's go ahead oh he's down here all right so we should be good to go let's go ahead and run it so we kind of spawned inside the monsters Arena but now when we exit we can see that we are now outside we go back in he goes back to biting so this is pretty much how we're going to uh code our behavior for our guy here is that when we're close enough uh he's going to attack and then when he's not close enough he's going to move towards us so that's as simple as it needs to be and uh I don't really want to complicate it too much um we're going to have to add in the movement and the tracking and that's going to be the hardest part but then we're pretty much done I mean the rest of it easy stuff so congratulations and we're uh going to do something here just to make this a little easier for us we're going to go to our monster guy and clect uh select uh add a new a new node and we're going to say uh text uh 3D should be oh um label label 3D sorry label 3D create it and we're going to call this state label uh what this does allow us to put some text in a 3D space so we're going to drag it above our guy's head here we can click on that and go to the inspector and then we're going to say text and we're going to set this equal to something there uh right now it's just a bunch of gibberish and we've also got to spin it around let's go to transform and um rotation 180 there we go now it's facing the right direction so uh we want to update this whenever our state changes and the way we can do that is by coming in here and saying if previous state is not equal to current state so if we just had a change of our current state because otherwise these two would be in sync then we are going to up upd dates the text of our state label so we can say State label and then we say do text which is uh this property here which just text so then we can set that equal to whatever we want and we're going to set it equal to the value of current state so now if we run our scene again it makes it a little more clear let me lower our guy down a little bit that right there so we can see that now he's in the idle State and as soon as we go in he's in the bite and then back to idle so that makes it a little bit easier to see and that also is a trick if you only want to run code one time within a uh when you enter a state if you want to run code as soon as you enter a state so let's say I want to run code one time and one time only when I enter the idle state if I hit this here and say print and it says uh I'm idle once that's good and the problem is if I do a print statement here it will always be idling so I'm going to say always idle and you'll see what I mean so we run this again and we just need to get out of here so it goes into the idle State and then if we exit out we can come down here and since that's running 60 frames a second right there uh it's printing out always idle a ton of times but I'm idle once only printed once because we only changed to this state one time while we're in it so usually it's good practice to not have stuff running a ton of times um so what we're going to do is move this animation over just so that it only plays once and we're not constantly playing the animation 60 times a second so we're going to do that for this down here as well and that may cause our animation to not play as well because we need to to Loop it cuz now it's only going to play the animation once not 60 times a second but our animation is already looped so we should be okay to go uh yeah so now our bite should only play once let's give that a try so that time it went into bite and it only played it once because it's not constantly playing that animation whereas if we go to idle because that animation is looped it's just going to keep looping over and over again but now we go back into bite one quick time and then it's done so that's how you control something running multiple times and running one time my my cursor was still stuck there but yeah so adding that check statement to make sure it's uh we're coming from from a different state so let's start adding in the navigation so our uh monster can start finding us what we're going to do is go to our best level and then we're going to click add we're going to add a navigation region 3D this creates a region for our enemy to walk around in and we do that by baking the mesh but first we need something to bake too so if we look at this a navigation mesh resource must be set or created for this node to work so if we say new navigation mesh we now need to make some stuff for it to navigate around and we use the meshes that we brought in from blender I'm going to use the standing plane and the buildings because those are the only two things the character I mean the enemy really has to watch out for uh they can't bump into the building and they can only walk on the standing plane so I'm going to take those two meshes and move them into the navigation region it only works with meshes it does not work with static bodies or Collision shapes they have to be meshes so then we grab our navigation region and we can actually let's hide all that stuff for right now so once we press the navigation region and we have those two meshes there we're going to hit fake nav mesh and that creates this uh nice blue area and this is where our enemy can walk so our enemy can walk anywhere where these meshes exist and then we're going to have our player as a Target and what it's going to do is create a list of positions um following our player around and then we'll feed those positions to our monster to have him follow so it sounds complicated but it's not that bad so we go back to our monster guy now and we actually need to add a node to him we need to add a nav uh I believe it's navigation agent 3D right there so we're going to create that and all we just have to do is have this guy here and then we're going to reference him through code so I guess we'll go ahead and jump on into the code now all right so I have the navigation going now I'm going to demonstrate it so we have the guy following us our monster and you can see he's in the chase state which is another state we created and we'll demon we'll show how it works in a second when he gets too close we move to the bite and then he stays there until we move away and then he's in the chase again now he's just moving to follow us he doesn't rotate to uh face us or anything like that we can fix that later and he can follow us uh anywhere that our navigation region 3D that we baked earlier is so he couldn't follow us over there but we would also fall through and if we do fall down he just kind of hovers there but let's uh see how we made that work so there's our navigation region 3D that we baked earlier we need that it communicates with this node here the navigation agent 3D going to our code now we had to do a few things the first thing we had to do was get a reference to our player and we create an onready bar here to have a global variable called player that we can access anywhere we then on our ready function so when this node enters the tree we get a reference to the player uh we use the function get tree which gets the tree that holds all of our scenes and then we say get first node in group and when we made our node uh player over here when we added it to the group Player it is the only node in that group so when we run this level it's going to go to the scene tree which is the node Above This that holds everything and then it's going to say get me the first uh first node that's in the group Player and player is the only node so it's going to return that one every time as long as it's there if it's not there it will cause an error so you need to make sure you have at least one node in that group so then if we print it out since we already ran the scene we can see it down here uh that's the name of the node and then this is the actual ID of the node so now that we have our player we're going to give that to our navigation agent and tell it to Target that but uh first we have to call our um Chase function so we have this chase state right here and when that's entered we enter the chase function and since it has to do with movement we're going to need the Delta variable which we just pass in because we're already in the physics process function so we get down to chase here and uh we take our navigation agent and condense that into a variable because we don't have to we don't want to have to write this out every single time and we are taking our velocity which is a built-in variable from our character body 3D and setting that equal to the next path position of our navigation agent minus our current position uh we normalize that and then multiply it by speed and Delta and all this is irrelevant that's just to uh sync it up to the frame rate don't worry too much about that but this is what we really need to focus on this is two Vector 3es being subtracted and that gives us basically the the path towards our next position and so what we do do is if our distance from our player is greater than one unit away from ourselves this position is our our self right here we could even say you know self. position that would run too but so we're checking the distance from the player and ourselves and if it's greater than one then we're going to update the Navigation target position to the new position of the player because this runs 60 times a second and then going to move and Collide so that will just move us towards the player so that's only if we're um greater than one unit away if we were like on top of the player we would stop advancing toward them towards them otherwise we would get an error but so all of that combined will allow us to follow the player and this is Vector math it's kind of complicated uh you can look up um subtracting 3D vector it's interesting but I would just you know uh there's a lot of tutorials showing you how to do this so I don't remember it every single time I usually look it up I also forgot to mention that we are entering the chase state from the idle state with pretty much no logic we're just telling it to jump into the chase state uh I just did that for Simplicity sake we probably won't use the idle animation at all because there's really no time when our enemies are going to be idle they're always going to be uh chasing us so um the next thing that we need to do is uh really flesh out our monster and make sure that we can hit them and they can hit us so let's add a collision shape uh actually let's add an area area 3D and this is going to be the actual body for the monster let's add a collision shape 3D on there and let's say this uh monster hit detection and then we'll call this um hit Collision hit Collision all right there we go and let's go back to our inspector here we're going to make this one a sphere shape and it is going to be attached to the monster mesh and then we'll move it up and then of course we're going to have to grab the hit but and make it a little bit bigger we're going to make it just a little bit bigger than the actual object here uh that way the player doesn't feel cheated if they shoot pretty close to it but don't hit it I think that's a good way to go and uh you know what we're also going to do which I think is cool is we're going to add a critical area to the eyeball over here so let's um add here and we're going to add another area area 3D and then we're going to hit it again and add a collision shape and then we're going to call this uh I crit and then um we can actually we won't really have to rename this one it's going to be on the I crit so we're going to know what it is uh and let's make that a sphere as well and let's make sure to make it a child of the monster um glb import thingy and then we're going to move the area 3D move the whole thing up to I would say right here and uh yeah I don't think we're going to do it for that eye we're just going to do it for this one and then if it works we'll duplicate it and figure it out figure it out dude uh we're going to go to Monster hit detection we're going to go to node um signals and uh actually no because our shotgun is is going to tell us what we collide with so let's just put this into a group actually let's go to groups and we'll put this into group um enemy and then we're going to put this one into group uh critical critical all right so let's go back to our shotgun now and we'll go back to the script and this is where we hit uh where are we checking for the hit scans fire where are you at okay if Ray is colliding print ray. collider all right so now we can do this um if Ray dot get Collider that is in group and then we can write separate logic so so it is in the group enemy we'll say uh uh Ray dogit collider and then we can call a function here so what we're going to do is say uh take damage and we'll just give it an arbitrary amount of damage we'll say 10 we'll give the enemy 100 points to start with and then we're going to do the exact same thing so we can copy and paste slam that down here and then this time it's going to say if enemy is in group crit uh or do we call it critical yeah I think we call it critical so then we'll do 25 damage instead of 10 so let's see how that plays out so uh all right so now we need to go to our get collider which is our enemy and we need to make sure they have this function take damage and it takes an argument so we're going to contrl C to save that go to our monster guy and then we're going to hit a new function it's actually leave those variables right there and create this function right here take damage and we'll just say num we're getting a num we're going to print um and we'll say we took uh num damage damage that way we know how much damage we took and we'll add some health bars and some later but um yeah so whenever we shoot our monster guy it should print this out so yeah let's give that a try yep we're going to go ahead and run it oh okay so I think uh we're not colliding with areas with our um we're only colliding with bodies so we need to change that we need to go to sorry it's probably confusing we need to go to our shotgun and we need to go to our aray holder and check out our rays and go to our inspector and right now it's only colliding with bodies so on our monster guy it's colliding with our monster guy's body but but it's not colliding with these because these are areas so we need to go back to our player and go to our uh sorry go to our shotgun and then go through these Ray casts and say collide with areas as well we could do this through code but you know I don't want to over complicate it for everyone and this makes it very visually understandable what we are doing let's give it a try now we'll save that go to best level run that and then if we turn around see is that working uhoh non-existent function take damage and B area 3D oh yeah uh it's trying to call that makes sense so right now we are trying to call uh this node right here and we don't have any functions on this node right here so let's just um there's a few ways we could go about this so we could actually add a script right here this is a you know this will show you how you can pass variables between scripts and we'll get rid of all this we'll say funk take damage and then we'll uh say num here and then we're actually going to say uh get parent. G parent so what this does is we're this node right here we're going to get our parent the monster and then we're going to get our parent the monster guy and that has the function that we need so then we just pass on the function take damage num and so we can actually copy this just contrl C and we'll go down to I crit as well press uh scripts we're going to get rid of everything in here contrl V contrl save crl s I mean and uh now we should be good to go and um let's actually take the shotgun and our shotgun does not need to collide with bodies so let's take this off all right so there we go um because we're only going to be shooting at areas and the bodies are only for contact of the environment and so now we can see that we are lighting up when we get on the circles but not down here so are we hitting him got to shoot him a few more times I feel like all right so no I don't think so I'm not sure what going on let's go back to our shotgun collide with areas let's go print and say here and then we're going to copy that and put it over there as well yeah there we go I think when I'm shooting It Forward right here oh that's what's happening okay so yeah the uh this is an area 3D um so that is eating up all of our input I'm pretty sure if I turn this off right here which is what we're going to do we're going to get rid of that uh that was just for demonstration we can turn this back on and we go here and now we can uh see oh I guess it I guess it doesn't actually turn it off you know let's just go back to monster guy and we're going to take this here and delete it and then where we have the this one we can uh go ahead and get rid of that function because we're not going to be using it anymore so let's um yeah let's go ahead and run now we can see that we have critical damage as well as regular damage yeah that other area 3D was eating all of our input so it was taking all the bullets before they could uh hit anything so yeah there we go so we have another issue and that is that our guy chases us but he doesn't face the rotation that our character is um running in they should be facing us so they can bite us or spit on us at all times so let's fix that we go to our script let's go to our monster guy um we'll go up here and what we're going to do is actually add a new node here and it's just going to be a basic node 3D and we're going to call it uh face Direction and then what we are going to do is uh say that face Direction and we're going to use a function called look at and that takes a position and the position we're going to give it is the character's position I mean the player's position so player dot position and then we also have to give it a vector to tell it which way is up so we're just going to say Vector 3 dot up and we can look at this function to see how it works but um basically all you have to do is give it a thing to look at and then tell it which way the world is facing up so that's what we've done here and then that means that this node the face Direction node is going to perpetually face our player whenever this code runs in the chase so now we need to do is update our rotation on our um actual monster guy to face the player and not just this face Direction node so let's go ahead and say rotate on the Y and then we're going to use the de to rad that we've seen before it just transfers degrees to radians we're going to do face uh sorry we're going to do a face Direction rotation doy and we're going to multiply that by turn speed which is a variable we have to create and let's just put that up here uh this will allow us to turn faster or slower and let's set it at um I think. 3 let's try 0.3 see how fast that is so if we run this now it should work we just added these two lines uh these two lines right here let's go ahead and give that a go so is it it is rotating to face us just very slowly so let's up the turn speed to uh two maybe that's too fast but you know so now yeah now it's turn to face us at all times that's pretty cool so that's uh pretty good now we just have to add some logic back in to make it bite so how are we going to do that well we already have the um answer kind of looking at us in the face here so if we're close enough to the player to make a stop we just have to grab this right here and let's just grab that line contrl c contrl v and let's say if we are within is less than two units then we will go into the next state equals bite and then when we're in the bite State uh let's go to our animation player um on our monster guy we need to get out of the bite state so we need a way to do that and the way to do that is once our bite animation ends we'll send a signal so we'll go to our node signal um animation finished we'll connect that to our monster guy and then we'll say uh we'll use a match statement we're going to match ANM name and we'll close this real quick and let me just uh put byes and then we'll put our logic in here and so then we want want to say next state and we'll set that equal to chase so after we do the bite we go back into Chase on the animation finished Let's uh see if that works I'm going to turn off the visible Collision shapes and uh yeah so let's see how close do we have to get before he bites pretty close uh let's turn that up a little bit on Monster guy I think he is going to the bite I don't know I couldn't really see it um let's go back and so that's within if our distance to the player is less than two so let's go less than four uh actually let's go less than five less than six Okay cool so we're getting there um we probably be at what what do you think four two more units closer that way he's munching on her face yeah see then we're actually getting hit by it and I think we do need to lower the enemy down just a little bit let's go to our monster guy 3D right here uh I believe that we can just lower the whole monster down maybe right there I think maybe up just a little right there let's uh run that scene now see how that looks yeah I think that looks a little more reasonable and Bam comes in for the bite all right so uh next thing to do is start kind of adding stuff like um let's go ahead and add a blood spray we're going to add particles we're going to do actually you know what we're going to make the particles a separate scene we'll go here uh make a new scene and we're going to say particles um let's go GPU GPU particles we're going to go to the inspector and we're going to uh oh we don't need to add anything else we're going to click on these and then we have to make new draw passes I'm going to use a uh let's use just a sphere mesh we might as well and then a process material we're going to new particles processed material we're going to add the gravity can actually stay where it is the emission shape is what type of shape they come out of so we're going to change that to a sphere and I think we're going to do is set some initial velocity on them uh much less than that maybe 10 make sure this is 10 too and then the direction we're going to I think set so one should be straight up because we want it to come straight up like a blood spurt and we're going to change this to let's go like 40 and we're going to come down here and change the material to a new standard material and we'll make it uh let's just make it red make it blood red and we can even go to our um thing here let's make these smaller because they're going to be like blood droplets I think right there and then we can decrease the segments because we don't need that much definition on them oh let's go with 16 or something that's fine and uh yeah let's save this as blood spray enemy all right so then we're going to change this to blood spray as well okay so we're going to go back up to the time we'll set the time to 3 seconds and then we're also going to add explosiveness to one and one shot to on so it only emits one time we're then going to add a script to this and we'll create that and we're also going to add a another node and that's going to be a timer and what we want to do is we don't need any process we just need the ready function when the node enters the scene we're actually going to start the timer and when the timer's done we're going to delete the node so we just have that one little skirt of blood and then the uh the node deletes itself so it's not taking up any more resources so let's go to our timer and click on the Node go to time out and connect it to the script and so then all we have to do here is Type in uh Q free and that is going to delete whatever node this is this is the same as saying s if you just leave it there so it's going to delete itself which will be the blood spray node so now we just need to spawn this whenever um we get shot and we do that by adding this in as a variable to our scene we can add a lot of things in as variables so on ready bar and we'll call this Blood spray we're going to say equals and then we're going to say preload which is a function and then we can select whatever we want to preload in this case I want to uh do this whole scene so I'm going to drag that in right there so that's how it looks and that means we're going to preload this scene and now we have to instance it all right so let's go ahead and instance the blood spray scene whenever we get hit so let's go to the take damage function and then we want to say uh bar blood equals blood spray do instantiate and then we'll say uh ADD child blood so what we do is we create a variable called blood and we instantiate that from the scene that we pre-loaded earlier which is our blood spray scene we have to instantiate it to make it real and then we have to add it somewhere in our scene so we add it as a child of the monster guy node and so I'm not sure where it's going to spawn on the monster but let's uh go ahead and give this a try so now when we run the scene when we shoot our monster we should get some blood spray or maybe not okay let's uh go back to our monster guy so we are for sure taking that damage let's try blood. emitting equals true and then we will fire it off oh there we go so now it's emitting from where the base of the node is right there from the very bottom but that's pretty cool so what we're going to do is actually just change the position that it's emitting from so to do that we just have to add an offset to the uh position position of the blood so we're going to say VAR offset and sorry and that's going to say equal vector three and we're going to do zero uh let's go maybe five and then zero so then we're going to say blood. position plus equals offset and let's see how that works out for us oh I misspelled position well we should be able to click here position not position so a little too high so let's go three yeah so now it's erupting out of the uh our guy there so now we can start adding in UI for our player and our enemy so next we are going to start making some UI for our player that's a user interface basically our HUD heads up display what we're going to be seeing when we play the game because right now we have no idea how much ammo we have or how much health we have we don't even have a Crosshair so we're going to fix some of those issues so let's go to the player scene we're going to be clicking on the camera node uh clicking the plus sign to add a node we're going to add a new control node and control nodes are what you're going to use when you want to make UI and when we click on our control node it brings us into the 2D mode so we're going to be in the 2D mode creating this thing and you won't be able to see it really anywhere in our 3D view Until We Run the game so it's a little annoying but uh it's easy to understand once you start start going so the way that gdau decides how big this control node is going to be is it uses these anchors and we can go up here and select how we want these anchors to be aligned I am here we go anchor presets I'm going to do full uh full wct so it's going to get the entire camera and now we can start adding nodes onto here I'm going to add a label and I'm going to add another another label and then I'm also going to add a texture so this allows us to add images and this allows us to add text so we'll go to this label here and write um this should be our health so for right now we're just going to type Health in there this is going to be our ammo and then this will be our current gun so we're just going to call this current weapon maybe we could actually spell it right all right and I think this one was health and then this one was ammo and then we can go in and move them where they should be so we're going to have our weapon over here our ammo over there and then our health is going to be down over here to the side so we'll call this player UI and now we can basically make references to these in our player script and then update them whenever we need to change stuff so we'll go to player and uh let's make a new variable called Health at on ready our health and we're just going to set it equal to 100 for now and we're going to create a function update health and we'll just put pass until we bring it down uh let's actually we need to create another on ready VAR on ready VAR and we'll call that uh Health label and uh yeah we're going to set that equal to let's add our um dollar sign and we want to set it equal to player UI on our camera 3D yeah uh no we want to set that equal to one more tab over and then we'll say health so there we go and then we're going to so how is this going to work I guess we're going to take damage so we need a take damage function in here let's close that up close up the input function as well so we need a funk take damage and we're going to do the same thing that we did with the uh enemy where we just pass in Num and then we're going to say health minus equals num and we'll do if uh if health is equal to or less than less than zero then prints oops we are dead nice so that'll just alert us if we're dead assignment is not allowed on the expression what do you mean I guess I have to put the equal sign over here yeah that makes sense like guess I'm an idiot um all right so take Dam image and then we're going to say update health and then all we're going to do here is set our health label do text equal to uh we need to get our um Health but this is a number and we need it to be a string so we do this St Str and we wrap it like that and that will convert it to a string so instead of it being an integer it's a string that way it goes in the text field we can't put a integer into a text field so that covers our health and then uh eventually we'll have a function for um uh heal player and we'll just do the same thing basically um Health Plus equals num update health so now we can come up with some type of like med pack or something put that in the game and then whenever the player crosses into the path with it we'll just run this function and that will update our health all right so now we can start thinking about our shotgun with our player cuz if we look at what we have uh we have to update our our health and I mean we have to update our ammo and our current weapon here on our player scene but our shotgun is going to be a different scene sometimes it might not even be loaded on our player so the way we're going to address that is by adding this camera holder into a group uh well actually we can just do it here we're going to call this uh cam we'll just call it cam why not and you can see over here now it's in a group and then on our shotgun here we can actually call that group so what we're going to do is create a function and that's going to be update ammo and uh I guess we really don't need to pass in anything here we just need to say get tree. call group and the group we're going to call is Cam and then we need the method or the function we are trying to call on that group so we haven't made that yet so let's go back to our uh Cam and we'll say funk um what are we going to call this one this will be update ammo update ammo and we'll have a number that we'll pass in and then we'll get uh just do a real quick um get node uh we need to get node ammo there we go and then we're going to set the text equal to a string from the word I mean from the int num so this is going to be a number pass it in make it a string and then set it equal to the value set the value equal to the text said the text equal to the value sorry all right um yeah so that'll do we just need to go back and complete our function here uh we call it update ammo and um we need to pass in uh what do we need to pass in um ammo in gun yeah we need to make the method update ammo the function or whatever you want to call it we need to put it into string form and then we need to tell it what it's what group it's calling uh all this does is call the group and then execute the function you put here and then you can pass in your arguments here so I like to do that uh I think it's a good way to communicate between nodes so whenever we update our ammo uh we also need to do the same thing contrl C actually you know we can just pass in two arguments here uh ammo in inventory I believe we can do that or maybe we should do it this way we need to put a comma in between these and then put this into a list so now we are passing in a list that contains the ammo and our gun and the ammo in our inventory and we're passing that to the camera holder up here into this function and uh we'll call this numb list we have to change this around a little bit num list um that's not correct uh num list zero that'll be the first index in the numb list and then we also need to we need to create another one uh another label so we're going to call this ammo sorry label create this will be uh inventory inventory ammo we can um add another one here we're going to put the inventory ammo and we'll say do text equals and we're going to do numb list one so yeah that's should do it we're passing in the list here we'll just print that out when we do it so let's see if that actually works oh that's right I never actually updated the ammo so now we need to update the ammo whenever we reload or do anything so um after we fire I guess all the r all the way uh we can just put it right here update [Music] ammo and at the bottom of reload we'll say update ammo and um yeah that should be it because we have one on fire and one on reload so we should be good to go yeah can't set it ah we forgot to do this scr there we go now we have two rounds one round zero we reload and now we have three two one zero reload and uh way up there in the leftand corner is our inventory so let's um fix that up just a little bit we need to go to our player UI uh let's go to our inventory ammo we're going to bring that bring that down here and then our current weapon and what we're actually going to do with this is take pictures of our uh weapons in blender and then use those as our uh image to go in here because we can put whatever texture we want in here so let's go ahead and do that all right so let's get the images from blender so let's uh close this down and we're going to open open blender I already have one open so we'll see if my computer handle is having two open and then we're going to go to uh let's go to our uh where's our shotgun yeah shotgun there we go and we're going to add a camera and then we'll press o to go to the camera oh we already had a camera never mind on uh let's delete that camera uh I'm going to press G on the y g on the Y to bring our camera back or we can press n Go to view camera to view and then now we can move our camera um I'm going to press and get rid of that panel and I would like to go here we're going to make this transparent by clicking this transparent in the uh render tab under film you got to click transparent and now if we go here and we go to rendered you can uh let's just gz move that up out of the camera view and let's see how big do we want this to be that would be huge let's just go with um 300 by uh it's 50 that sound good yeah okay um maybe less than that yeah let's go 200 by 50 g on the Z just going to bring our camera up just a little bit and uh yeah let's render that image oh we still have alt H this in the background gz I'm going to bring that up then we can render our image so so that looks all right uh image save and let's go to our documents uh I [Music] believe from scratch uh I forgot where the our thing is at test project assets level whatever um oh that's right we have a weapons thing all right now we're going to go shotgun. PNG save his image we can jump back into gdau if we click down here and go to weapons and we should have shotgun PNG we can then drag that into our texture there so that's what we're going to see let's just uh Run the game and see how that looks uh run this this game see how that looks okay cool so we have our shotgun down there let's go ahead and do that with the other guns so go file well I won't show you guys that part that's stupid um but yeah we have the main components of our UI now we just need to switch the guns out so let me make two other guns all right so I have the other weapons in now and we can take a look at them so the first one is this uh little daringer 22 pop gun and it loads uh one round at a time we can shoot the enemy with it we can uh go up we already saw our shotgun uh we're calling it the boom stick we have our Mac 10 and this is actually automatic so we can hold it down and then uh we can reload and it remembers our ammo between um changing weapons we have our Glock so we can reload that as well and then uh we're back to our 22 pop gun and you can see we're still down the three ammo that we shot at the beginning same with the uh shoot and Scoot so we have an ammo system we can change guns and uh all the guns can do damage to our enemy so uh I'm going to go over them kind of briefly because they all work about the same way as our shotgun did so our shotgun has let's take a look if we just condense these down we only have the process function which takes our input just uh you know whenever we press the fire and stuff like that tells us if we can fire or not and then we have the reload which reloads are gone the fire which fires are gun the update ammo which just calls our um UI on our player uh it updates the ammo count down here so if we go back to our shotgun uh yeah so that's all that does and then this just El alerts alerts uh whenever our animation finishes and this moves our um pretty much drives our shotgun so that helps us change uh back into like reloading and stuff like that so that we're using that exact same animation driven process on uh pretty much all these the Mac 10 uh same thing we can see we have the reload fire update ammo and then whenever the animation finishes we just get to shoot again the thing is the animation on this one the fire animation is super short only like one second long uh I mean 0.0 a tenth of a second long so we can fire much faster than the animation of the shotgun which is uh let's see 1 second long and the Glock is uh about the same we have um the process take the input the reload the fire update ammo and same thing and the only difference we have in the daringer script is that we have this add initial ammo which just adds ammo to our gun um initially because this is going to be the first gun we have the 22 pop gun we're going to start with that gun cuz it's like like um you know kind of a starter weapon type deal the next thing we did that we have to address is we can see our enemy here when I shoot him he goes into a recoil State uh We've added that cuz he also moves backwards a little bit so we've added that to make it a little more um you know it's just more fun uh so let's take a look at what we did to our monster guy we'll go here basically what we've done is add a another um add another state so we have this recoil State here and we basically take the opposite of the direction we were moving in in the chase state and go that way that's all this does if we look at the chase Direction um we have the next PATH position that we get and then we subtract our position uh to get where we want to go towards the player so if we reverse that by adding a negative sign we'll move away from the player so whenever we're shot we move into these uh this recoil State and that will launch us backwards and we uh we switch to The Recoil State when we take damage so this is the function that we're actually calling when the raycast hits the um the monster so we have that Flinch sound that we added then we say next state recoil which moves us into into here we come from the chase state to The Recoil we jump backwards because of this line and then we just play uh we play The Recoil animation which we added to our monster which I think I just like made him look up or something let's take a look at that yeah I just kind of tipped him up a little bit so no big deal there we've also added a sound to our um our monster here but you've already seen how to add audio players so uh you should know how to do that and uh yeah I guess we'll continue on so just thinking about what we needed in a weapon system we needed to be able to purchase weapons off the wall with points from killing enemies and then have the player be able to switch through all those weapons so we're going to be starting off with our little daringer pistol here and the way I did that is by going to our player and instead of like we were doing linking it through here or uh instantiating it through there we're actually instantiating it through code so our player script on our player node uh up here at the ready function this is where we actually instantiate our daringer from a packed scene that we preload and so then when we want to change guns we actually are using U this script down here I put the input call here that way we can kind of separate it out from our player and make it easier to uh debug so what we have is if event is action pressed uh change weapon up this is a new um event action that we added uh change weapon up I didn't do it on camera sorry but it's uh the mouse wheel up we already showed how to add these so whenever we scroll the mouse wheel up we'll change weapons up just cycle it up like any normal FPS we then have our weapon list and this is the weapons that the character will have available to them so if I go in here and put Mac 10 then we will be able to switch to the Mac 10 so right now we just have daringer uh shotgun and Mac 10 but we don't have the Glock so if I go back in here now and say Glock we run that again I can switch one two three right to the problem solver or the Glock so that's how we're going to control what our character has when we start off we're only going to have just the daringer and then as we buy stuff off the wall we're going to add it in here so we'll just add this string in and that's really all we have to do with this pickup weapon function we're going to call this from um whatever node we want whenever we like step on the weapon to pick it up or buy it we'll just call this function send in whatever we want so we could say shotgun it'll say weapon list. append that adds it to the end of our list so we'll have shotgun added there and then we can switch to it so um the actual cycle weapon up function is right here the first thing that we do is get the current weapon and we get that by checking our first child since we are the weapon holder our only child should be the weapon that is currently being used by the player so when we get when we get that first node that is our get children gets us a list of our nodes and then we get the first node in that list and then we say get the name of that node so we had our daringer it'll return daringer we had shotgun it'll return shotgun so then we check if that gun can fire because this whole thing is going to be cycling our weapon to the next weapon and if we're reloading or firing we don't want to be able to switch weapons we then get the index on the list that we are currently at using the find function so if we were the daringer coming in uh we had that equipped we would be at index zero we would then check to make sure that we're uh not out of bounds or we don't have a negative index and then we also check to make sure that we don't have uh we're not going over so like if we were on shotgun instead of going to index number two that doesn't exist we flip back over and go to daringer that's what that line down there does and right here when we switch the guns out we actually need to record the ammo count for the gun so let's say we have the shotgun and we shoot three rounds and then reload and we have uh whatever five rounds left or whatever in the inventory we need to record that and we're recording that in this this dictionary up here so these are the initial amount of rounds each um gun will get three rounds in the gun for the shotgun and six rounds for your um inventory for the Mac 10 30 in the gun and 60 for the inventory and so on and so forth so when we save them we save how much ammo is in the gun and how much ammo is in the inventory and we save it to these values in this dictionary so we can call upon those values whenever we need them and uh we just call this function down here we could have had all this written into here but it's easier just to call the function and then send in the values we can use gild uh. name and get. ammo and gun because we all because they all have that um this variable in uh in them so if we go to our Mac 10 you know we have ammo and gun and we go to our daringer ammo and gun and we go to or Glock it's ammo and gun so they all have this variable that is updated whenever they are reloaded or being shot so we can always check that variable to get their ammo count so that is what we do beever uh before we um Q free the previous gun and load in the next gun and that is where we Q free it right here and so then we have to spawn our new gun so the return index is going to be whatever our current index is Plus one unless we have to loop back around and so if we uh once we get the return index we're going to spawn the new gun and um here we have another match statement where we are checking our weapon list where getting that index so right now if we were the daringer and we pressed up our return index would be one because we are at index zero return index would be one that would be our shotgun we will come down here go to our shotgun and uh I'll demonstrate here just cuz I have uh all the code this part updates our UI to tell us you know what um gun is currently equipped all that stuff down here this uh actually creates the instantiation of the gun this adds it as a child to our node um basically adding it to ourselves this node right here the gun uh right here is where we are we're setting the ammo that is in the gun and the ammo that is in the inventory from our dictionary so if we saved it previously here now it's going to be returned uh to this value here because we have it saved and then we update the ammo which is the function um that just updates the UI so it should say update ammo UI but it just says update ammo all it does is call and tell how much uh ammo should be on the screen for the player sorry that was badly named let's go back um the daringer offset this just gives it a little bit of offset so it sits better for the player to see and we just change the position so that's all we do um is to update the UI instantiate the scene add the scene as a child uh update the ammo that that's in the current gun and display that to the player and then set the position of the gun where it should be so we do that for every gun down here and that's what the match statement does uh is will it will uh set us up for whichever gun we pass in so that is how we did all of our Logic for the uh weapon holder all right so we're really at a point now in the game where um I've showed you pretty much how to code a lot of stuff and most of it is now just flushing out the game we're not really adding a whole lot of new mechanics uh the only thing that I've I've done a lot of work um away from the uh video but most of it has been just me changing up the environment and changing up some of these textures to make everything look better uh I used AI uh Bing image creator to make these textures I'll just pull that up real quick so uh you basically can just type in like space station seamless wall texture and uh use one of these or you know um I did like some food stuff uh because I have these like rotating things that just display images um that are pretty cool so I just AI generated some stuff uh for that and put those in there this monster guy I made in blender and and it's very easy if you know how to do curves you just basically make a bunch of Curves for tentacles and then um add some bones and have them flail all over the place just like we did for other character you parent the bones to them and uh yeah we then import him as a scene all that stuff just like we did our enemy um I had to change up the navigation a little bit I had to change the size and the height of the cells as well as the agents the agents are the things that are actually moving around in the world and the cells are the cells that they move in so I just had to play with the settings they're probably not perfect but I just did it to uh have it so that they wouldn't get stuck on walls and also that the um uh they can kind of come over here and kill the character they can like come through here they would get stuck all around here and they couldn't get to you but now they can come in and find you if you're in this little shelf area so um yeah that was the major changes another thing that we did is uh there's a cut scene I've also added this thing which is uh the hand info station and if we go in here we have this hand and all this really does is just tell us what current level we're on we're going to have five levels of enemies so it's just going to display like 1 2 3 4 and five and then every time the level changes there's going to be like a tone that emits from the hand saying like uh the level has changed or whatever we also hung the guns up on the wall all it is is just an area and uh when you enter the area if you have the amount of money and you press the E button we can buy that gun off the wall and then it gets added to the dictionary on our player and if we go back up to the wall after we have uh um like we bought it and then we go back and we already have it in inventory it's going to buy ammo for that gun just like in uh zombies so we come over here I think I put the wrong gun up twice I need to put the Mac 10 up but then I have this statue which doesn't do anything it's just there for the cut scene um that I made and we can keep going uh that's pretty much it that I've added um textures are all changed I added a Shader from gdau shaders uh um I think it's gdos shaders Donnet or whatever I'll have a link in the description but they have a bunch of free shaders you can use and you just got to copy and paste them um these torches I think we made them in blender and then I've just added those particles to them uh yeah I'm going to have like a little Easter egg whereas if you shoot all these bugs it'll play a song um and then I added some uh you know just like that this is actually going to revolve around those images are going to change out and uh yeah that's pretty much it uh let me just go ahead and and play it now and you'll see what the game looks like we don't have an ending yet we only have the um five levels smoke him if you got him so it's probably pretty loud I might not do a whole lot of talking the hand declares it is level one ouch so we start off with just this pistol and uh we can shoot them and if we shoot them in the eyes uh we do extra damage and we get all blood whereas if we shoot them just in the there Gold Blood and it does more damage too so if we shoot him in the eye it should kill him instantly yes dude and uh yeah we probably could make the weapons a little bit better and make them kind of shoot where they're aiming but this is more for demonstration than anything else so you can kill them yes dude trying to get buy the shotgun yes dude yes dude so they still get stuck on some stuff but it's really not as bad and especially once you shoot them they have them little backups they usually unstick themselves so I mean for what it is I'm okay with it so can we buy it the hand declares it is level two so I can't buy the shotgun I must have forgotten to code that one yet but we can buy this roock ouch yes dude maybe slow but right okay yeah we can't so let's uh yes [Music] yes yese dudee ouch and then anyway when we die we get this all was well you were eating alive and uh yeah and I'll just show you the beginning intro I was the maintenance guy at the occult Space Museum it was just me when a package appeared I opened it and a statue flew out of the package landing on the ritual altar inside the museum at first I thought my years of substance abuse had finally caught up to me snapping my final tether on reality but in actuality the artifact had a mind of its own landing on the Slate it completed an ancient alien ritual allowing unspeakable Horrors into this world the artifact communicated with me psychically it said past the five trials and receive our blessing I had 2 hours left to my shift and I was almost completely sober I decided I'd have to handle it management would flip and they knew the new guy set off his space curse on his first [Music] day smoke him if you got him all right and then we just come back to here so for the most part this is the end of the tutorial um if you've stuck around we've done like UI we've done some weapons we've done player movement we've created an enemy from scratch and blender there are some things that I did end up adding to the game uh just for my own Amusement uh I added a boss fight and uh that is with um let's see if we can even find him um yeah so it's this guy here he has a few attacks he can either summon people or um uh you can summon more of those monsters to come and attack you that we made earlier or he can spit like three little bolts of acid at you uh the way I made him is by using this program called uh make human might take a second to load but yeah this is a free program uh just you can get make human community and it's from a website you can download it and it will make meshes for you so you just select like you know gender male uh male female you can choose the age um you can do muscle weight height like that so um yeah geometries you can add t t-shirts uh materials you can add faces so all I did was just add make a really weird face and then in blender I cut off his legs because you can file uh if you go to file here and you go to export um you can export it as an fpx and then you can actually upload that to uh mixo if you want free animations or you can um just bring it into blender and make your own animations you can even add a skeleton here uh let's take a look where is it pose animate uh yeah game engine skeleton um default no toes so yeah I sometimes use the game engine skeleton here uh I think it works all right if you're just making like simple little things so I like this program I use it all the time to make simple human models it makes it way faster and plus you can add like teeth and eyes and stuff and that's just hard to make in blender so you might as well automate some of your processes yeah so uh anyway that's the boss fight um I'm going to upload this entire gdau project to my itch and uh you can download that and then you'll have all these things to parse through so you can see how I coded everything um yeah uh thanks for watching uh if this helped you out please subscribe um uh probably more to come have a good one