 Today we're going to be creating a marble game in which you will have to wall to your objective. So as always starting with an empty project and one texture which is the texture that we're going to use for the wall. But let's start with that. Once we create the 3D scene we can start adding all the nodes that we want. For the level I'm going to be using the nodes which are here in visual instance, geometry instance, csg shape and primitives. These are all shapes that you can use in your project to make 3D things as a mock-up for your levels. It's not meant to be used for the final thing but for making small game jump stuff should be enough. The nice thing about this is that you can combine them and you can use them to create other complicated shapes just in case that you need some extra flexibility without opening an external 3D program or anything like that. So let's go with a box. Box is what we're going to use for the tables where the ball sits and everything. So let's create one. As you can see here you have just the block nothing really complicated and on these points that you see here one on the top one on the left one on the right you can drag and drop it and you modify it how the shape looks. So if you do it like this it goes wider then thinner then longer. So you can start using these elements to create your level. One cool thing about the data is that you can move freely by pressing the right click on the 3D scene and using the WASD keys. So it's like an FPS game where you can move and the camera moves with you and if you feel like this is very slow you can also use the scroll wheel and your movement is gonna be so much faster in this 3D space. So this is really useful whenever you're like previewing or doing some level editors that you can navigate freely around your scene. Now that we have this plane let's create our character in this case the marble that will fall down until it reaches the objective. So since we want the marble to have some physics and everything we're going to use another kind of node which is here in spatial collision object physics object rigid body. This will be our marble and when you create it it's empty there's nothing in it because the information of what collides and everything you have to add it afterwards. Let's hide this box for a minute and as we had it on previous episodes if you've been following or doing any 2D tutorials like 3D Ingo.Works really similar to that so in the same way that whenever you add a kinematic body you need to add a collision shape and a sprite here you have to do the same you have to add a collision shape and a sprite in this case since they are not sprites although you can use one you do a 3D model. So in this point that we have here let's let's add a child node which will be the collision in this case collision shape we created and on this shape we should we choose shape new sphere shape this will give us a sphere which will be the collision of this object you can make it bigger or smaller the same way as the other node like so but we want to do the default size we're not modifying anything right now and now we want a representation because if we play the game like nothing is really there so we need to add a sphere going to the same nodes we can search them easier by typing here csg sphere and we have a sphere here it's very blocky it's not really appealing but you can modify its properties here so if we want to add more radial segments and more rings the ball will get smoother and smoother you can go nuts with this one to make it really smooth or not another alternative if you don't want to use these kind of boxes is i'm going to remove this one and instead of doing the csg box let's add a mesh so here we can search for mesh and here in mesh instance we do almost the same as with the collision shape we select here a sphere and we get our sphere here it's much smoother i think it has better defaults so i'm gonna stick with this one for now let's make sure that we don't modify anything let's press this button and we close it so we have our player here now let's display again table that we have before and move the ball on top so that when we play the game the ball will fall on that there's one thing we have to do i wanted to fail first so you see why now let's add the camera camera this is how the player will see your scene when are you press play and you can move it like any other object here using those arrows or the circles around any of those 3d objects makes makes it rotate so you can rotate the camera you see that square is where you are looking at and if you're confused about what the camera is actually looking at you can use here on the editor pressing on preview and you can see what the camera will see this button will show up whenever you have that node selected so if i don't have that node selected you don't see it but make sure that you can select it press preview and you see it so let's move this into a place there and let's press preview this looks okay let's spray play now and let's see what happens without a game of course we save it as main and play so the ball falls and that was the order i was talking about because although we added collisions to this rigid body we didn't add any collision to the box and since you are going to be creating complicated things with this one there is an alternative way instead of having a collision shape you can here press use collision on this inspector option and it will collide with everything they have on this layer in this case both are on the same layer if you see here layer one okay so you should collide no problem okay we see the ball it falls there let's create some elements to make it look a little bit closer to what the game will be just to try things out and continue with the visual aspect later so let's move the camera a little bit behind okay this first i'm gonna make it a little bit steeper so the ball whenever it starts it goes and i'm gonna make it longer so we can move it much more then okay let me move it here now whenever this goes there i'm gonna duplicate this one control t and i'm going to create another one and let's make it so that this one is let's see on the opposite side like so so the ball will fall over there it will look like this and so let's try it out we see the ball falling which is the other side it goes all the way up and then it falls down okay so let's now create the level let's make it so that you first start falling on this one then you have this one to bounce and okay i'm gonna select everything here i can do it like so i should select everything i can move it on top so i'm not under the grid okay and i'm gonna duplicate this one and move it to the other side so we can reach the end okay kind of like this so the ball will go here all the way there and you have to move there and at the end we're gonna have this ashtray kind of thing where you can finally leave your marble there and that means that you win maybe let's make this a little bit smoother okay so it's not that too if you know what i mean okay so let's start creating complicated shapes with these boxes i'm gonna create one which is going to be the same a box we'll have it at zero let's go there let me get a bit bigger and now since i want to add a hole on it i'm gonna create inside of this one a sphere csg sphere this sphere now it's inside of the other one like they are basically the same kind of material and everything like it looks like it emerges but here on the node options there are different operations union which make them together intersect and subtract subtract will do a hole in this other shape so for instance now we see that the ball is carving a hole inside of that other structure so in this case we wanted to be a little bit maybe bigger yeah move it a little bit on top and make the box a little bit taller and let's put this here so it's not okay and then clicking outside okay so here we have a hole on this square let's move it a little bit on top so we don't see the grid okay and here we have it this structure for now it's gonna be where the ball is gonna fall you can use these kind of combinations to do anything and if you want the opposite right now we're using the operation subtraction but if you want the opposite you can use intersection so it will only draw whatever is intersecting between those two if you work with vector graphics this will be very intuitive for you and if not just try it out combine some shapes add subtract and you will understand it pretty quickly okay so we have here our goal our end goal and let's place it where we want it which is there at the end so I'm gonna select it and move it there see okay okay we'll have it there it's gonna be kind of easy to get but it's okay for a test level we have now the basics of our level and let's start adding some of the interactions because if I press play you're gonna notice that the camera is not moving you're gonna do anything with the ball so it will just fall and nothing will happen so let's start setting up the camera in a proper angle that we want if you want to preview the camera and move it at the same time if you press here on view you can split the viewport in two and now that we have two I can use this one for previewing the camera and this one for editing the game so in this case let's move this a little bit top and this is the angle that I want maybe a little bit further okay something like this seems okay and we can remove this view now okay I'm gonna go ahead and create a script for our camera which we'll call camera.gd we will want to update the position of the camera to be following the ball so let's first get the distance from the camera to the ball and then update that same distance all the time so we're gonna hit the offset and we also want to have a reference to our ball so on ready bar ball with capital letters it's gonna be get parent and get node rigid body so this line of code here is gonna be accessing and saving this reference so we can use later on ready let's set the offset for the first time so the offset is going to be the translation translation is when you click on any of these objects here in transform the translation is the position so if you move it you see that those number numbers are gonna move so that's what we want to get that's the same as position in 2D so we want to get this which is a vector 3 and let's subtract the ball translation okay so now we know that the offset that we have to respect on every step now on Fang physics process translation is equal to ball translation plus offset so in this way every step is gonna check the position is gonna set the offset that we calculated at the beginning like the distance that there is between those two and it's gonna move the camera at the same time let's try it out and the camera is following our ball and it falls okay so now we have to start adding the code to our ball so we can move it a little bit to the sides so let's attach a script it's gonna call it ball and the Ciclera variable that is called movement speed and set it to 0.05 something really small and then we can modify it if we want to and in the Fang process let's start with the user input if input is action pressed i'm gonna use the default ones which are the arrow keys and every empty color break you have this but you can modify and create your own so let's start with ui left pass so i don't get the error and let's copy this and ui right for the other one okay and now we can apply central impulse central impulse will make that this node suddenly has from the center like some impulse that makes it both magically you're not rotating anything you're just adding like some invisible force but since the ball is gonna be rotating we're gonna see it rotate wherever we want it apply central impulse let's create a vector 3 in this case x is going to be movement speed the variable that we created and the rest is gonna stay as zero and same is going to happen in the other step instead of adding positive movement speed we're gonna subtract the movement speed let's try it out and see how it feels if we can move can present left right okay i made i made this on the other opposite side okay so this one has to be the negative and it has to be the positive my bad let's see okay yes i can move the ball now i can stop and here it goes and i think i forgot to add a collision there yes i forgot okay let's add use collision and i think that you can clear the level now so let's try it out again okay and it goes there okay success we have our first level working let's now make this look a little bit better let's add some extras first of all if we add a texture to our ball we're gonna see it rotating better so let's start creating a material for that we get a close up here we select a rigid body and remember that the mesh instance is what we are actually seeing and here on material we don't have anything let's add a new spatial material you see this new resource appears and when you click it you get all the options here you have a preview and the one thing that we're going to be using on this tutorial for now is the albedo which is the color or a texture in this case if you modify the color you will see that the ball changes the color to whatever you pick but in this case we can leave it on white and add this texture that we have here it can be whatever you like i like this one for this marble because it looks kind of okay and when you add it you see that we have here our texture applied on the ball now when we play the game you see it actually rotating it's now more clear because before it was white you couldn't tell the difference now i want also to have that glossy effect so let's modify this and add roughness let's move it lower lower lower lower so you see that it's kind of glowing the roughness basically means how a material is so if it's really smooth it reflects you will see here that it has kind of this glossy so it looks kind of nice another thing that i see in a lot of these tutorials is that you see those sharp edges that you have around the objects and especially when you're playing the game like you can see them those lines i don't really like them so i'm gonna go here on the project settings and on the rendering quality you can add the msaa which if you played any game you know what this is you set it to 4x for instance and every of those edges is going to be super sharp if you see here now you can see it even in the editor this makes it look so much better and since we don't really know exactly where we are and if we start creating complicated levels we need to have a better reference let's add some lighting so let's add a node and in spatial visual instance light directional light so you have these three kinds of lights they have very good description at the bottom so this is basically a sun this is basically a light that you have in a point which is like a circle and this is a spotlight which points to something if you want to have it just like a spotlight but we want just to have a sun and whenever you create it you can see the difference between those i don't know if i can toggle yeah if you toggle you see that everything gets eliminated and this fake sun that you add you can set the direction by the rotation of it so if we want to have the sun having from one side pointed from one side you see this white arrow over there you can rotate it and you see how it moves let's do it at an angle and also a little bit looking down okay kind of like that i think that this position doesn't matter the only one that matters is the position of the arrow because the light is going to be global it's going to be affecting everything another thing that we would like to add is in this directional light you can enable shadows so you press here on the shadow whenever you have this node selected you enable it and you see here that you the elements cast shadows to the other ones and this makes it look really good let's make the sun go from the top so okay so we can see the marble light let's see how the game looks like right now okay starting to look much better okay yeah you can also do the same to these platforms that we created here if you select one you can create different materials for them so let's go ahead and create a new spatial material and only change the color with i'll be let's make it something like light green something like this and if you want to reuse some material to different objects i recommend you to save the resource so i will save it as green material and you even get this preview here which is really cute i like it that whenever you have a lot of those you can set it and let's select the other ones so this one and here in material i can drag and drop so you set the material and here you set it and on this one we're gonna leave it at white because i feel it's a better end goal okay this is starting to look like a game i really like it another thing that you can change is the sky this is the default sky and if you don't know exactly where to modify it you have to do it on this resource that you have right here which is the default amp default environment you can make an image like an fps you know do you have those images of the sky like a skybox uh things like that or you can create a procedural sky which is the one that is created here on this default resource by setting the sky ground sun texture whatever since this is really colorful let's add some some nice colors let's see some pink on the sky always looks nice the horizon let's see i don't know maybe some green to make it more cool futuristic kind of surreal and oops and for the bottom color let's go with that dark purple purple let's see okay and horizon color let's go with something like a red okay so let's make it a bit more darker okay let's play the game let's see how it looks like i want to i want to feel how it looks here okay much better okay here we move it the level is super easy for now but yeah okay now that we have a cool sky a cool level i'm gonna cover the last thing that you might need in a small game which is checking whether an object is inside another one if you follow the other tutorials in my channel you already know how to do this and if you've been seeing how easy everything here is it's because it's really super simple to create things since 3d and got out it's basically the same as you do it in 2d but you add an extra dimension which is the sea but the rest is pretty much the same in this case we're going to be using an area and checking if something is inside that area or not the same as in the box tutorials so we want to check on this node so let's create a new child node it's going to be collision object area we have it here and as any other area you need a collision shape so let's add a collision shape inside of it and this collision shape is going to be a box shape this rectangle that you see there this box is how big it is so the same as before we use those sliders to make it bigger and let's make it a bit taller okay and it has some signals so the area has the body entered and let's create now a master script for our game as we always do and let's link that whenever in this let's rename this to end this area when a body entered let's connect it to the game let's add our rigid body our player there our ball let's add it to a group so here in groups so we don't have to check for that instance and you can create as many marbles as you want there's a very popular twitch game which consists in a lot of marbles going through a level which you can create a clone of that with all this knowledge like you don't really need that much for the physics stuff if you want to do multiplayer that's another story okay so now that we connected this on the game we check for if body is in group ball don't remember if it was capitals or not yes it was capital letters okay print you won so you can replace this with a dialogue with a menu going to the next level with whatever you like since i've covered that several times on my channel i'm not gonna create the entire thing uh so let's try it now that on the terminal there at the bottom it says you won let's see speed running this already okay here you won you see there the message whenever we reach that area i don't like that it's doing that thing with the camera that it it's overlapping so let's modify this one maybe the last thing that you would like to know is that if you want to add some text elements or something control nodes related you can create a canvas layer which is going to make a new screen and inside that canvas layer you can add control nodes and here you can do the same as you did in any other tutorial here let's create a label which says hello from a control node and if you see here the the size of the screen on your canvas layer it will show up on top of your 3d game there we have it at the top so if you want to add a thank you congratulations for finishing my level and trying this game whatever you can do it there okay so that covers all the basics now to try and make this level a little bit more interesting gonna do like a timelapse of me editing this level and see how we can use these kind of basic shapes to create some interesting levels okay so i've been playing with the editor a little bit i created this level which basically makes the ball go at the beginning you have to move on the side this basically is like a tutorial for the games if you don't press anything you will lose but if you start moving you will notice that you can move that way you see that the speed goes there and goes very fast and then when you get to this curve which is actually a bit slower than i wanted then you get to this part which you have to use these columns to make the ball go slower because otherwise you will go super fast and you will miss your target so this is something really busy you have to do but i notice a few extras that i want to cover here first of all the camera is not rendering all the distance so if you see here on the preview we cannot see the end of the level and since we don't have a lot of things on the screen let's make here on the far let's make it longer okay so now this will show how much you see on the camera in this case we want to show all the level another thing is that i want to give the move the movement a little bit more impact so i'm going to rotate the camera a little bit so that makes you feel like your ball is rotating so let's go to the rigid body and here let's get the reference as we did before with the camera to get this let's get the camera from this one so cam is going to be get parent get node camera so we should over the bar sorry okay so okay we should get the camera over there and let's rotate it we want to rotate it in the y angle so camera rotate y and this has to be super super small i don't want it to be super strong so let's go with zero zero one and the same on the other side but as always to the opposite direction let's see if it's like this or not i'm confused now okay okay yeah this adds more dynamism to the ball moving okay now you can feel that you're rotating the camera oh maybe it's even a bit too much let's make it rotate a little bit less let's go with zero five okay yeah this is more closer to what i feel that i'm pressing on the screen okay let's follow okay now that we're fighting that you can go to your ball and maybe you want to make it go faster let's see the gravity scale here is one let's go i don't know let's try with three because this will make it the ball much faster so it's gonna be harder you see but it's i think it's more realistic than the other one the other one was super slow yeah now this is a challenge let's see how it reacts when i collide okay oof almost fall okay yeah this one is much harder so you can tune these values here the gravity the weight of the object and anything and as before you can keep creating some levels and hope that this is useful for you to create any game on a game jam you can use these same principles to make a puzzle game or or even the the same game that we did before with the box you can with the box pushing you can do it here in 3d um and as you can see it's really really simple like Godot makes it really simple for you to to create 3d games in no time so this is for today and it was a lot to cover i hope i was able to make it as short as possible because i don't want to make things too complicated but i hope you enjoy it and i really want to thank my patreons and all your support if you are not subscribed please subscribe leave a like it helps the channel a lot and see you guys next time i will probably go back to one of the previous series and more updates on the dialogue system are coming soon so thank you very much again everyone for staying here and see you guys next time bye