GameMaker 3D [EASY] Only 3 Scripts | In Depth

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if you want to know an easy way to make 3d games with game maker or if you're coming here from my previous 3d tutorial you've clicked on the right video as requested by Ignacio sloth boss this is a more in-depth tutorial on 3d with game maker let's dive in so let's just go right into the project files first I'm gonna show you guys my sprites that I have made so here I have my sprite from my player now this is just a very simple breathing animation only four frames and this is just what I've created and now here I have another 2d image just kind of this little animated sci-fi incubator here with bubbles coming up and now here it's gonna be hard to tell what this is because if you play the animation it doesn't look like how it looks in the game and that's because we actually have we're programming our 3d obstacles differently than our 2d obstacles which I will go into later in this video for now I'm just skimming through these it's the background and then we just simply have our camera object which is X or excuse me camera sprite which is actually invisible so let's open up these three scripts the first one SCR underscore depth underscore 3d so let me just explain exactly what this is doing global Z is a global variable that I've set myself now global Z is actually set in this project in the player object if you're doing a larger scale game I might recommend setting that in the camera object or maybe not necessarily the player object there are some better ways to do this but this is just simply how I've done it this is not the best or the most efficient way but this is how I've created this and I found is the best way for me so basically the z-axis is going to be where our camera is facing so the camera and the z-axis are all going to be the same thing so if your camera rotates to the left your z-axis is rotating to the left and basically what this determines is where things that are being drawn in a 3d or a pseudo 3d way need to be drawn in order to look like they are 3d and look like they are alive in this world rotating with the view so this is simply this entire script right here SCR depth 3d all that this is doing is this is telling your objects exactly in what order to draw themselves and that has to update every time that your view or your global Z is updated so if you'll notice here at the very bottom your camera rotates with your global Z but basically all that this is doing is so typically in a 2-d game you would want to set your objects depth to negative Y and what that does is that will set things to where if they are lower on the y axis then they will be drawn in front where if they are higher on the IAC's excuse me if they are higher on the y axis which would mean that they were behind an object that's lower on the y axis that they are drawn behind so this is this is a very common so in in many 2d games of very very common depths to do program depth would be something like depth equals negative Y program them in the step event so this is basically taking that and this is saying okay well if you're facing how you would normally be facing in a 2-d game then your depth or your z axis is going to be negative y same here the reason that there is two of these for facing north is because the way that the direction works its 0 to 360 so you kind of have to break these up I couldn't do if global Z is greater than equal to 315 and less than negative 45 because then it would be it would be all kinds of weird and you get glitches from that I'm sure there's a there's a way around that but this is just I've just done it twice here I'm so facing east so if your global Z or if your camera is facing to the east then it's going to so your camera is going to be rotated to where you're actually looking up on the x axis and so then obviously if you're facing south it does positive Y instead of negative and then west is going to be negative x so all that this is doing is this is just telling the objects in what order to draw themselves and this is the best way that I found to do it I'm sure there are better ways and more efficient ways but this is just what I've created and so here is where we actually link the depth with the z axis and now if so basically this since we're using numbers somewhat outside of well so in the player that the player controls the global Z with the left and right buttons and so since we're using real numbers in that and not actually technically using direction which is 0 to 360 we have to limit this so that it doesn't go to for example 365 or to negative 3 and so that just catches this keeps it in that range and then here we're setting that so done with the first script now this is like I mentioned in my last video if you if you didn't see that part of this comes from a script that I used that heart beast did a did a tutorial on and that is over sprite stacking he's not the one who invented it but he's the one who actually showed me how to how to make that and how to do that and basically that is let's see here that is this right here and then everything that I've done outside of that is my own implementation so basically normally if you're doing sprite stacking you would stack the sprites on the y-axis if you're not familiar with sprite stacking I definitely recommend checking out heart beats video I will put a link in the description but I will do my best to explain it basically you're taking different parts of the sprite and you're drawing them on top of each other with an offset so that it makes them appear 3d so that's why this looks you know like this whenever it's animated but in reality since we have implemented the sprite stacking script into this 3d object it's not going to be drawn as that type of animation it's going to be drawn so if you see those cubes now what's happening as I'm rotating the camera that's updating our global Z which is working together with our view angle so our camera angle and then the way that objects are drawn is also playing off of of those things together so there's a lot of connected pieces here and if you'll notice so now I am drawn behind but if I rotate now I'm drawn in front and that's the SCR Dart I don't remember the exact name of the script at our depth script so heart beats does a way better in-depth tutorial on sprite stacking I don't want to touch on that too much I just want to kind of give you guys the basics of that so basically all that I'm doing here is I'm just basically setting a few parameters in place so that we know you know basically hey instead of drawing only along the y-axis draw along the z-axis the global z-axis that we've created which we create in the player event which I'll go over here in a second rather than just on the y-axis like in a normal singular view angled game now this is also important to set the image speed otherwise all of these frames that it was drawing standing still would be so they would essentially look like they're flashing through this animation every single one of them and that's not what we want for sprite stack and we always want that image speed to be zero I'm sure there are a few different reasons you might not want that for example if you were doing you know maybe some sort of animation on that I don't know that that would be tricky to pull off and there other ways to do it but yeah we want that image speed to be zero third and final script and this one is the easiest okay I mean this is just some really really advanced stuff here people so hold onto your seats because I don't even think programmers at Harvard would be able to crack this one so all that we're doing here draw sprite ext we're drawing so whatever the frame is so you know whenever our player is breathing whatever frame 0 1 2 3 and then we're drawing or excuse me that that would be for the image index I apologize sprite index the object of the player has the sprite player we're drawing it at our X at our Y which this is actually um centered at the base now it's important to Center your 2d sprites at their base because in the real world if you're looking down at something you would want so from a kind of 3/4 top-down perspective you want them to rotate at this point rather than in the so say in the center because then it would just look like it's kind of rotating in a way that's not natural to the world that it's in so we're rotating or we're excuse me we're drawing at the X and y but then we are rotating so rotation is going to be long global Z from the point of origin and we're using the image X scale image y scale which typically is positive one but if you want to do a squash and stretch script you can implement that as well we're drawing it white because that's going to keep its original color and giving it an alpha of 1 it's going to be completely visible there's not going to be any transparency to it if you wanted transparency you could do something like 0.5 or if you wanted it completely invisible for some reason zero so yeah that's that's probably the most basic script out of all three and now I'm actually going to show you how these are implemented into the objects so this is just simply a collision parent for since we're programming or since I've programmed this entire project in the physics world using the box 2d physics this is just simply all collidable objects get this so the player collides at the 3d obstacle and it collides the 2d obstacle and then these all take on this collision event where the box 2d physics is handling all of it for us so that's just simply a parent object now the player object has the bulk of the code like I said there are better more efficient ways to program this but this is just how I wanted to program it there always there's always going to be a better way just program it and get it done and then you can clean it up if you wish so it uses physics and now here's something that's really important when you're doing the collision shape for these objects you want it to be at the base because the player you know the head right here let's say an enemy comes behind the player or you know we don't want it to stop right here we want it to stop right here so let's say this 3d obstacle we don't want to collide with our head because our head is you know in a 3d space it's along the z-axis we only want it to collide at our base so for all those always make sure and do the base now create event we are setting the animation speed to 1 you can set it to that's you know not entirely necessary it just depends on your animation that's just how fast it's going so like like I said here we're setting that global Z I said this earlier I want to say it again I would recommend if you're doing a larger scale product project maybe doing this in the camera object but just for the sake starting out at the create event your global Z or your view angle equals 0 and then we're just going to create our camera object which is what the room follows and then we just have a very simple yeah I'll just I might as well literally this is the only code in here yeah so this is just a very simple smooth camera it doesn't perfectly follow the player it has a little bit of a delay that's literally all that it does and then it's just being created at the create event ok now in our step event we are calling that depth so remember SCR depth 3d this this just determines in what order this is drawn either in front or behind really simple there and then for our draw we're doing draw sprite 3d now we're not doing stack because this is a 2d image we're just simply having this drawn rotated along whatever our global Z is in that very instance keep in mind if you don't already know this the draw event actually updates every single step it's basically like the step event but specifically for drawing now key left and key right this is just the rudimentary camera controls so we're doing either you know when you're holding left it's rotating to the left by one degree at a time and then the same with the right and then that's why here in I believe it was this one we have these locked is because so right here we have this locked because in the player we're just simply using numbers so 360 plus one plus one plus one plus one you know that's gonna be above 360 and so we're just locking it in that script now this is just very simple WASD movement but there's a little bit of a trick to it so we are using using length Durex and length or Y and so we're basically our movement is working in tangent with the global dot Z and so yeah essentially we're just subtracting different amounts of degrees so whenever we're moving upwards for example yeah our player is moving along the x and y axis in direct correlation with the global Z okay so we have all of those now if you'll notice some of these have this little flip here and some don't a and D are the only ones that have flip all that this is doing is this is flipping our character to the left and that's why we we went in here let's see which one we went in here and we did image X scale and image y scale instead of one because if we had these set at 1 which is the default we would not be able to actually flip our character depending on to the left of right where they're facing now you could change this to where you actually have four or eight different directions to make it look more 3d I just did a basic left and right just so you kind of get the example of what that was and then that would be you could either do it based on where you're moving or where you're where your mouse is position there's all different kinds of ways that you can do that and so this is just an emergency game end since we're going to fullscreen that's not really super important and then we're just inheriting from our parent here so we've pretty much got the bulk of this code out of the way the rest of this is really easy so yeah this is just calling the 3d script the same one that we use in the player to determine the depth at which it's drawn and then we're also doing the same when the player uses it just rotates it from its base along the z-axis we've inherited from the collision and if you'll notice our hitbox is at our base and not taking up the whole sprite like in a side-scrolling 2d game so now this one operates differently than the 2d obstacle because there's two different ways to do it this is where we're still implementing that 3d depth but we are now calling for the sprite to be stacked rather than drawn along the z-axis so it's still stacking along the z-axis but if you'll remember it's yeah check out heart beats video he does a really good job at explaining that and I probably did a terrible job earlier and so for this you would actually so this technically is going to be the base and then it would be drawn extended upwards or extended in whatever direction the z-axis or the view angle is facing so yeah it can collide with other there's physics collidable objects and I already already went into the camera it's just a simple smooth camera script nothing fancy about that and now let's just check out the room properties really quick and this is pretty much the last thing so yeah we just have a few few things in the room right here and if we go to yeah we just have we just have this that is the repeating background just a little simple grid and then okay well let's check out the viewports of the viewport yeah nothing nothing crazy here we're simply following the camera object and then for the room physics since this is a top-down game make sure to enable physics in all of your rooms and then make sure to not have any gravity set like a normal 2d game otherwise everything's gonna fall negatively on the y-axis for no reason and remember they're already on the ground and you know we're not using any any gravity so yeah that's that's pretty much it here's one final look at some of that gameplay and you you can really expand this a lot you can do a lot with this this is just simply a way to get started and then you can kind of let your imagination go from there but yeah there's a there's a look at the project file more in-depth explanation I absolutely love getting comments like this one from egg locks it feels really good knowing that I could help somebody and even if I can just help one person my job here is done the reason that I started this YouTube channel was to help you whether you're a beginner an expert and you know way more than me I simply feel that I owe it to the game maker community to pass on the knowledge that I've learned over the years and I still have a lot to learn myself I still have a far way to go but in the meantime I'm always going to continue passing on my knowledge just trying to help as many people as I possibly can so if you liked this content and you'd like to see more please consider liking or subscribing every subscription and like helps this channel grow and I can reach more people and hopefully help just one extra person really make the games that they want to make if you did find this tutorial helpful please let me know in the comments below I'd love to see what you guys are making and if you are struggling over anything or if you have any tutorial suggestions or even if you'd like to just chat with me I'm always willing to engage with you in the comments but that's gonna be it for this video I will see you guys in the next one
Info
Channel: Backspace Cadet
Views: 12,251
Rating: undefined out of 5
Keywords: echorobot, gamemaker, tutorial, how, to, gms2, videogames, video, games, make, program, pixelart, pixel, art, game, development, dev, 3d, zaxis, axis, z-axis, zed, 2.5d, psuedo3d, psuedo, fake, fake3d, NIUM, indie
Id: T58VzYWoW30
Channel Id: undefined
Length: 21min 17sec (1277 seconds)
Published: Mon May 20 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.