How To Make A Doom Clone In Godot 4

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] all right starting out in a blank scene here I can use the scroll wheel to zoom in and out uh click the middle Mouse button to look around shift click middle Mouse button to pan around let's click 3D scene here double click rename it to World Ctrl s save that's our scene our main World scene let's do Ctrl a again or you can press that plus sign let's add another node 3D rename that environment now Ctrl a mesh instance 3D let's make a plane uh geometry material override standard material 3D click that Albedo change the color let's do I don't know some like dark red or something and we can rename that to ground and I don't need physics on it because this is going to be essentially a 2d game and I don't need physics on that because this will be essentially a 2d game then control a again another mesh instance let's do a box this time do create try mesh static body geometry and give it I don't know blue color or something so now it has physics you can see there's a static body 3D and a collision shape on it so zoom out I'll hit our switch to scale mode these are all the different modes up here um so I'll just scale this up to give us a big four and this one I'll rename to block if I hit f i can sort of focus on it if I'm over there W switch back to movement mode and I can move it up maybe I'm gonna hit r scale it up maybe scale it out a little and move it over there Ctrl D to duplicate Bring It Around I don't know make a few blocks now we want our setup our lighting and stuff so what you see here this lighting and shadows and stuff this is just like kind of default editor view if I actually run the game I hit Ctrl a let's add in a camera 3D here and move it back I can hit preview you can see there's lighting but if I actually run this hit F5 we need to find a main scene so click select current if you run it you can see there's no not actually any lighting this is just default editor view so we want to add an environment so just add World environment click new environment here you can change settings in here like background color whatever you want stuff like that I don't care I'm just going to add in a control a directional light 3D so I can bring this up and E rotate maybe rotate it around here you can hit T to toggle between local and Global transform by the way click Shadows enable those now we have shadows and lighting looks good okay now if we just test that you can see that there is Lighting in our scene it looks good let's delete that camera now let's click to create a new tab we'll click other node type in character body 3D so this is we're going to use for characters that are have physics and interact with the physical environment rename this to player click node groups type in player add that so now it's in the player group we can save the scene also here go back to inspector control a let's add a collision shape and give you a capsule shape it does W control drag that'll snap if you do control drag so bring it up now we need a few elements here so we want a recast 3D this will be for the gun I'll bring it up I'll set the target position to zero and set the Z to be negative 1000 and I bring it up to 1.5 on the position so you can see it's pointing really far that way we also want a camera 3D move it also to 1.5 so now this is kind of our guns pointing the same direction as our camera from the center of the camera so now we have all this uh let's just do our UI so I'll do control a at a canvas layer so canvas layers are typically where you want to show UI and we'll do Ctrl a add in a control so control nodes are used for UI I'm going to call this gun base and if I click here I can set the anchoring I'm going to do this one as Center bottom and we're going to do control a and add in an animated spray 2D so now let's go ahead and add in our assets so I'm just going to drag these into the scene and there you go they're in so under animated Sprite let's do animation new spray frames go to animation non animation click that there we go I brought up spray frames editor so let's call this one idle set this to be play on awake we click this little grid thingy here choose the gun Sprites horizontal one vertical I mean horizontal four vertical one select the first frame if I control scroll wheel I can zoom out so select that add one frame that is our idle animation there and so you'll notice this is a blue uh this has a blue icon here so typically red is 3D green is UI and blue is 2D but you can render 2D inside of the UI by just making it a child of a UI node right um so I also want to if I have q that brings me in select mode I can drag this by holding shift or alt shift and that yeah makes it Center it keeps it centered so in this case I want W I'll just bring it up I kind of want it to be at the bottom I'm going to hold uh shift bring it down like this and W bring it over a little bit so that gives me my gun uh and puts my gun in a good position at the bottom of the screen and let's do one more animation I'll call this shoot and again click that gun Sprites bring vertical to one and I'll click this this this and then this so it ends on this one you can see the number which frame it'll be add four frames if I play that you can see it's playing the animation I don't want it to loop I want it to be a little faster also so let's bring that up to 10. bam that looks cool all right so that is our gun animation there let's also add in a color rectangle and Center that make it really small just alt shift and then make the color more transparent and I'll call this a Crosshair there we go okay and now I want to add in one more UI thing I'm going to do control I'll call this death screen let's make this cover the whole screen and then I will add a panel and let's Center you and shift alt bring that up alt bring that there and let's add in a label and I'll say you died we can Center that and bring that up and then also a button says re-start Center bring it down there we go and let's just hide that one more thing let's do control a and let's add an audio stream player just a regular one with no spatial anything it's just gonna play at the same volume no matter where it is it has no transform at all and we're going to add on our revolver shot here and let's click audio down here add a new bus I'll call this sound effects so that way over here I'm holding this to shoot sound and over here on the bus it'll play the sound effects bus so that means it goes to the sound effects bus Which then plays through master volume so if I want to have some setting that changes just the volume of sound effects I would only change the sound effects bus volume okay so now finally let's go in we're going to add a script here so just click that click create this gives us a script template we're not going to use most of this we also need to have input and um yeah we'll start with input here so I'll do move forwards move backwards move left those typos all right exit restart and shoot if you make a typo you can just click the name change it there we go add a plus sign and then you just hit whatever input you want so move forwards I'll hit W click OK backwards s left okay uh right the exit will be Escape restart let's do R and shoot I'll just click Mouse button left Mouse button okay there we go we have our input also under project settings I want to set up our physics layers so we go down to layer names 3D physics let's name layer one to environment and Layer Two to characters um and on our player over here in inspector Collision put you on Layer Two so if you click the dots it'll show what it only show the named layers but you can also hover and see what they are so environment is going to be near value one layer 0. and we want Mass to be both of them so the way it works uh Collision in Godot is typically when you have something that's a physical object you set it to be on the layer you want it to be on and then you set the mask to determine what it can collide with so in this case I'm on the characters layer and I want to be able to collide with both the environment and other players or under other characters so now in our code here um let's get rid of all this jump code and let's get rid of all yeah all that we don't need that now we need all of our references so let's get a reference to the animated Sprite let's get a reference to our raycast 3D and let's get a reference to our shoot sound also on our raycast 3D we need to set the Collision so right now it's masked to just environment we want it to be able to hit characters as well and we don't want it to hit the player so we don't check hit from inside colliding with just bodies areas or something else we don't need to worry about and make sure that it is enabled also it's excluding the parents so it's not going to hit it anyways okay so now we have our speed already defined let's do constant mouse sensitivity let's say 0.5 so we can set up that and let's finally do VAR can shoot that's true so this will determine if we can shoot our gun and VAR dead which is false we are not dead then we'll have function ready this is called basically when the game starts or when this node is added to the scene if we instantiated it and um this is just a default method we're also going to have function uh input so this is called whenever any input event happens and it passes in that input event so I press a button I move the mouse whatever joystick whatever physics process which was already here that's like fixed update from unity and it's just called 60 times a frame no matter how fast or slow your computer is or not 60 times a second sorry we also have uh process which is called every frame and it changes based on how fast your computer is right and pass is just kind of like a junk line so it doesn't do anything but if I take it out it's then the editor sees oh there's a blank method so there's a syntax error so I just like to put that there because I don't like seeing syntax errors when I'm talking um so we have these are all our base stuff so we're going to have some generic input in here let's start with mouse input so first off if we're dead we should not be able to turn so we're going to say if Dead return otherwise if our input event is a input event Mouse motion so if I control click on this I can see what it is and we can see here there is a 2d Vector called relative if I click on that it shows oh it's a position relative to the previous position so if I move the mouse it gets how much I moved right so I can get the event.relative.x multiply it dot Mass sensitivity so this is if I move my mouse left or right we can do rotation degrees dot y minus equals that so that'll make us turn left or right then under process let's put some input if input dot is action just pressed or not yeah just pressed exit we're going to exit the game so we'll do get tree dot quit and that'll close the game and then for let's see restart we want to restart the game I'm going to put that in a separate method because I'm going to be able I want that to be called from the death as well so we'll just put that over here or from the death screen button so there's that and then finally um if we're dead return so this will be kind of our in-game input this is like I don't care if I'm dead I want to still be able to call this then we're going to have a shoot method here if we press shoot and you can just do Ctrl C on the line and then Ctrl V and it will copy you can also do Ctrl shift d and it'll duplicate the whole line so if we press shoot call shoot and we're not dead right um now um under physics process we want to have our movement so obviously we should not be able to move if we're dead right now it's getting move input from some predefined input stuff this is for UI I'm just going to put in my own input because it's uh more readable that way move right move forward move backwards there we go okay so this just takes our input converts it to a 2d vector and then this line over here converts it to a 3D Vector facing forward from our player so if we rotate the player it'll still work properly and then this just checks if that input is not zero so if our or yeah if our Direction input is not zero then set our velocity of our character body 3D so this this node has velocity built into it then yeah set the velocity to be that input times our speed um otherwise if we aren't pressing anything set our velocity to be moved toward the velocity to zero basically with this Delta so you can control click this method so you move toward just yeah it moves it from to my Delta so it'll just move it to zero then finally we call move and slide which actually moves the character body based off whatever the velocity is and if you hit something at an angle it'll slide along it and move nicely okay so now let's do function or not function we already have this defined we're going to do shoot so what we're going to do with this is if we cannot shoot then return and start off set can shoot to be false so we're shooting we want to wait for the animation to be finished so we want to play the animation so play shoot and then play the shoot sound oh wait we already have that defined shoot sound dot play there we go and then finally we want to check our raycast so if our recast is colliding so if it's hitting something and get the collider that it's hitting so that and if it has a method called kill we would just say get that method dot kill there we go so it'll call kill when we hit something we also now we need to wait we need to have a way to set this to be true so we're just going to say function shoot animation done and we'll do can shoot equals true and then so we need to call this so we go up to uh ready so in here we want to get our animated spray 2D and there is a signal on it called animation finish that is emitted whenever an animation is finished if you click on something you go to node signals and see all of the signals on it you can also of course search in the docs here animated Sprite and see there are some signals here right and it explains what they all do so anyways back to our script so when this is finished we just get that and we do dot connect and we put in the name of our method we want to connect to so it'll call that when the animation finishes also in ready we want to hide the mouse cursor input dot mouse mode equals input.mouse mode captured so captured makes the cursor hidden and stuck to the center of the screen we also want to get our death our button here so we can just drag this and it gives us the path and we just do dot um button up so that's a button up single connect and put in restart there we go so when we press that it'll restart the game now finally for restart we're going to do get tree Dot reload currency and that'll restart it and finally we need our kill method so if we die we want to do dead equals true we want to get a reference to the death screen so if you want to get a reference to anything you do a dollar sign type in the name of it or whatever and you can get the right it'll give you the path here and then that gives us a reference to it so I just want to say show so that makes it visible again and let's set the mouse mode I'll just copy that to be Mouse mode visible so it should be visible so let's go ahead and bring this into the scene so in our 3D scene here I can either click this or I can do Ctrl shift a drop in the player let's move you over here press F5 let's bring it and looks good it's shooting I can move around if I hit R it restarts if I hit Escape it closes let's quickly test that we can die though so if I hit R let's put a pound sign that Common Sense out type and kill there instead so when I hit restart it should kill me and I'm dead I can't move if I click restart the scene restarts there we go okay so let's just Ctrl X cut that line put it back how it was now let's create our enemy so new scene here other node let's do you could also click 3D scene right click change type and then change it to a character body and then we type in enemy and save that and put on we need a collision shape again do a capsule shape bring it up by one there and an animated Sprite 3D and let's do new spray frames uh click that we want idle and this will be play on awake click this go to Monster Sprites horizontal should be five vertical should be two select all these ones add those in if we play that we can see how it looks maybe make it a little faster and we want Flags billboard y billboard so now it'll face us if I have one on the numpad I can get the front orthogonal view so let's just bring it up to there bring down the pixel size a little bit maybe to like 0.009 so it fits in a little better that looks good okay now uh set our Collision make sure we're on the characters layer and Mass 2 environment and characters everything's good there so now let's just make our death animation so make a new one call this death gets our frames five and that play and get our death animation bring up the speed here we go okay cool okay so now uh one more thing is we want to add in a sound so let's do audio stream player 3D so it will play spatially right so when we die or when it dies if it's really far away it'll sound like it's really far away and let's just bring on our monster dye sound here put the bus to sound effects and if we test this let's call it death sound and if I play this [Music] it's you can hear it from pretty far away um so if you want to change that I can change the unit size to like two and you can see the circle that kind of shows the main area plays in if you zoom in now it's pretty quiet from up close you also adjust the volume DB if you want to make it just overall quieter or louder before the distance check is done um so there we got everything there so let's add a script for that uh I don't want anything in this template actually so I'll just clear that it's got a reference from this click drag hold Ctrl and drop it in uh let's do export VAR move speed in this case with 2.0 so doing export makes you can adjust it from the inspector here so you can see it shows move speed over there I can change that and then reset it also and also copy that let's do attack range as to also and we want a reference to our players so we'll do on Ready Player uh character body 3D equals get tree get first node and group Player so if you're familiar with unity this would be like get game object of a tag I forgot what it's called R dead equals false there we go so um yeah when ready is called we get the player get the character body and there we go and we're doing typing here so we can specify that it's a character body 3D by putting a colon and putting that after I could have done other things like float or something but I don't care it's not that important um so um now we want to do function physics process so we'll do our movement if we're dead return I don't care if the player is null return I don't care and let's get a direction to the player so bubble position minus r ene Global position and then we do Direction dot y equals zero and then Direction equals Direction normalized so basically if the player is on the slope we want to flatten the vector to get a horizontal movement Vector before we move then we just do velocity equals Direction times move speed and do move and slide and then we'll just always move in a straight line towards the player we also want to have a kill method so in this case dead equals true uh play the death sound so we'll just get a reference to it and we're going to do animated spray 3D Dot play death and Set uh our Collision shape to be disabled equals true alternatively you could also do Collision layer equals zero and you might have to do mask also whatever um so let's test that real quick we go into world let's add in a enemy here so run that let's see it's moving towards me and if I shoot him he dies but it's looping I forgot to turn off Loop let's do this turn off looping there we go all right um let's do that again shoot him okay stays dead I don't collide with him once he's dead good okay now let's add in um a new method we're called this function attempt to kill player and we'll get the distance to the player and if that equals uh position distance to player dot Global position if that is greater than attack range return don't do anything also let's put this in here oops there we go and then otherwise we want to get the eye line of us so Vector three dot up this times 1.5 oh my God I got an indentation error okay I was wondering why it was an auto completing um then we want to get a query so we're going to do a raycast query so we do physics Ray query parameters 3D let me create that so anytime you're doing a raycast or some sort of physics cast so I could just use a raycast 3D like I did on the player but I also want to show here's how you do recast from code or any other physics thing basically um you can use this you can also uh if I just search query I think it'll show yeah you can do a shape you can do a point there's some other info in there anyway so we're going to create this and we're going to create it from starting position will be our position plus the eye line we don't want to start from our foot because there could be a little bump on the floor and then we won't you know represent if we're actually seeing the player and we want to go to player dot Global position plus eye line and we're going to set the Collision Mass to be one so remember one is the environment here you see value one there and we just want to see if we have line of sight to the player that means we can hit the player we already have a reference to the players we don't need that um so and then we do the result so we want to get the result of our query so we do get 3D World get the space state of the world call intersect array with our query parameters then we just see so if we go to this method control click it returns a dictionary with all this information in it like what we collided with the hit position whatever we don't care about that we just want to see if we hit something so we can just see if result dot is empty that means we have clear line of sight to the player so just call player dot kill there we go now let's go back to our world we already have an enemy so I'll just run that comes up to me I die here we go I can restart okay so let's just add in some more enemies kind of get the feel a little more and you can see it's previewing with the death animation because that's what I left it on so if you want something that looks better put it back on idle and there we go now you can see that so let's run it and see how it is [Music] you can see I can't shoot through things they're also just walking directly towards me there we go now finally if you want to full screen this um well you can wait for someone to die you can click this it'll full screen but you'll notice that the gun's really tiny and yeah it looks weird and um it doesn't start full screen so you can go to project project settings search for window under display here you can go to mode full screen and then under stretch mode here do Canvas items now if I run it you'll see it is full screen and all the UI elements are the correct size finally if you like this tutorial be sure to check out my retro style 3d FPS course on udemy it covers how to make a quake style 3d FPS in Godot game engine I'm currently in the process of updating it from good O3 to good04 so there will be regular uploads of Godot 4 content on this course and of course you can still watch the good O3 videos too which are still pretty relevant to good o4
Info
Channel: MizizizizTutorials
Views: 46,746
Rating: undefined out of 5
Keywords:
Id: jzbgH4AMtI8
Channel Id: undefined
Length: 27min 57sec (1677 seconds)
Published: Sun Sep 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.