I Created My Dream Game

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
when I was six years old I had a dream in which I was playing a 3D game Flying the infamous snowspeeder from the movie The Empire Strikes Back I remember the frustration I felt after waking up and realizing I could not play that game since there was nothing like it at the time I thought it to be a romantic idea using my quiet knowledge about computer Graphics as an adult to make my past self-stream come true after my last project in which I built a 2d top-down space shooter using jet GPT I thought to myself wow this took me only one day to finish how about doing a similar simple game but in 3D it surely will not take me more than a week well it took me much longer than expected but I learned a lot and was eventually able to finish it in this video I will take you through the main aspects of the game so you will get an understanding of what it takes to translate our 2D game into 3D let's go we can take some inspiration from our window creation code of our 2D game one fundamental part that changes is the initialization of the renderer we will build our own renderer from scratch utilizing the opengl API to be able to render 3D Graphics first we need to initialize our window with the appropriate opengl flag and secondly we will use glad as a library that loads pointers to opengl functions at runtime there are many options out there but the benefit of glad is the ability to include it as a header only Library it doesn't get much simpler than that once that is set up we can test our code and our first step is done we got a window pretty underwhelming but we'll get there now let's get serious how do we actually render 3D objects there are amazing write-ups on the topic on the web one of my favorite one being learn opengl I will not get into a lot of detail since this would be way out of scope for this video please refer to some of the materials I mentioned during the video if you wish to get more details on any topic you may know that 3D objects in video games are usually built from a fundamental shape a triangle so let's set this as our first goal render a triangle to the screen for that we will declare a buffer object which holds all necessary data to describe our triangle that object will then be loaded into our gpu's memory using the opengl API having the data is not enough we also need to tell our GPU how to process that data that's what shaders are for small programs that tell the GPU how to transform the data in our buffers once we combine these Concepts we are able to draw first shape on the screen okay but we want to render something more serious on the web I found this amazing model of a snowspeeder following the data of the model into memory I made use of two popular libraries one being as SIM for handling the data format of our model and the other being the stb image loading Library following the same concept of rendering our triangle we will get something well clearly we are rendering the model we can see the exhaust grills but everything seems to mesh together and there's no sense of three-dimensionality we will need some serious math to get going let's start with some intuitive Concepts we want to be able to express the position rotation and scale of our object in 3D space we can express these with a scary sounding term called affine Transformations simply speaking these are type of functions that preserve the parallelism at relative distance between points we can encode translation rotation and scaling of a model into a matrix that we will call the model Matrix there will also be a unique Matrix in our scene called The View Matrix which represents the position and orientation of our camera imagine your monitor Center being the origin relative to our camera's transform by which playing our model Matrix with the view Matrix we will perform a transform into the view space encoding objects coordinates relative to the camera finally we will need a transform for giving our scene sense of depth that is what a projection Matrix is for depending on what effect you're looking for there are different ways to construct the projection Matrix in our case we want to perform perspective transform which simulates the way objects appear when viewed from a particular perspective or point of view after this final transform our model's coordinates will be mapped into a cube-like shape this is called the clip space since it Clips all parts of objects away that will not be rendered onto the screen given the current perspective once we got our objects coordinates in clip space we can let opengl handle the rendering of pixels onto our screen while this will be enough to get our 3D object rendered while rotating we still don't see any contras or Shadows that's because we have not described the lightning model in our Shader yet for this game I will stick to a simple blindfong lightning model adding some texture rendering and we got ourselves a nice snow speeder pretty cool to get any sense of speed while moving through our scene I wanted to create some terrain which Loosely resembles the snow Dunes of Hoth there is an amazing video series on procedural terrain generation on YouTube from a guy called Diamond death following some of his videos I was able to create my own terrain generation tool to create a simple world next I created a component for capturing user input and mapping that into role pitch and your rotations so we are able to control our snow speeder positioning the camera behind the model and adding some velocity to our flight code we have our first flyby the movement still looks pretty rigid and it doesn't look like we're actually controlling spaceship simple trick to add more sense of movement is adding some interpolation between the model's orientation and our cameras orientation now it looks like we're actually flying spaceship how cool is that what is the only next reasonable thing to do let's write laser guns to render our laser shots I use a simple technique to render 2D Sprites in our 3D scene which is called billboarding and now we are able to generate laser shots when pressing the spacebar for our enemy I found these amazing models of Death Star surface Parts I took the turret model and quickly imported it into our scene to be able to move the turret parts we have to introduce the concept of transform hierarchies basically any non-trivial 3D model will be a composite of several models organized in a hierarchy when applying a transform to a model up in the hierarchy we need to apply to the children as well we do that by keeping track of our parent and children in each model's transform component when updating the world Matrix of a particular transform node we need to multiply the parents model Matrix with the model's local model Matrix this way our transforms trickle down to the children models this can be seen here where the base part of the charity or rotation is also applied to the guns which is a separate model in the hierarchy now we just need to calculate the direction from the enemy to our player to get the updated orientation of the model when flying by we see that the turret follows the player correctly I also added a particle generator to the enemy to be able to shoot lasers speaking of shooting each other we should Implement a way to display our health bar for that I use this texture which displays an empty and full state of a health bar in our Shader we then modify the texture coordinate offset depending on the fill level thus rendering only part of the top half and part of the bottom half of the texture at the time here we can see the speed of our spaceship being rendered as a blue bar on top of our health bar next I want to add a sky to our scene this Shader simply draws a gradient and when applied to a huge sphere acts as a sky seems like things are going pretty well and smoothly what could go wrong at that point right let's talk about physics the most important thing to know for our game is when a laser has intersected with an enemy or the player to keep rendering time below 16 milliseconds physics engines assume simple shapes to calculate Collision detection testing each triangle in our scene would just take too long so first we have to decide on the geometry models that will represent our spaceship turrets and Laser shots for our laser we will use an infinite Ray and knowing the position and length of our laser shot will help us to determine whether the Collision actually occurred or not for our enemies and the player models a bounding box will be a good enough approximation for now having these models we can formulate the problem as detecting an intersection between an access aligned bounding box and array luckily we don't have to develop such an algorithm since this topic is very well researched on the web you can find this great write-up on an efficient implementation of the so-called slab method the idea behind it is pretty simple let's say we have this blue bounding box and two rays to understand the slab method we first have to Define what a slap is in the original paper the authors called the space between two parallel planes a slab in our particular case the two planes Define the access aligned bounding boxes extend along a particular axis to perform the test we first convert the array into the axis align bounding boxes local coordinate system and with then check the intersection between the Ray and the slabs you can also think about it as clipping the ray by each pair of parallel planes and if any portion of the ray remains it intersected the Box in this example we see that after testing against the X and y-axis slabs only a part of Ray 2 remains which means it collided with our bonding box why Ray one did not and finally we have a game we can detect the Collision of the laser shots and reduce the entity's health accordingly but my brain didn't want to stop there I also wanted to detect whether the player crashes into the ground for that we can make use of a technique called the separating axis theorem it is described in the Collision detection Bible real-time Collision detection we will be testing our player bounding box against the low resolution mesh of the ground thus testing against single triangles this algorithm works by doing a separating axis test for each edge of our shapes let's say we start with the edge of this triangle we construct a line by calculating the normal of the edge we then project every point of our shape onto that line once we have done that we find the minimum and maximum points for each shape the test then checks whether the intervals of the two shapes overlap if they do not overlap it means that for this particular Edge the shapes do not Collide and we have found a separating axis after implementing these Concepts we can see once our player touches the ground the health is reduced to zero and that concludes our physics system honestly this took me a while to get going but seeing it finally work was worth the effort now I want to be able to render some text on the screen so we can create a simple menu while this was pretty simple using the 2D renderer of sdl in our last project things get a little more complicated with our custom 3D renderer by checking the learn opengl page you can learn more about the details of how this works in general we will have to create a texture for each symbol and then render that to the screen we make use of the free type Library which is widely used for transforming two type fonts into texture data since I'm a pretty bad writer I asked our old French at gbt to come up with a short dialogue between our main character and a commander after showing the title screen we will play the short dialog as an intro to our mission I also added a picture showing the controls with sdl it's pretty easy to set up support for different input devices so I added support for my Xbox One controller as well for sound we can just make use of the same Library we used before which is STL mixer for obvious reasons I cannot play the music I chose for the game in this video feel free to check it out by downloading the game on each IO with every start of the game I randomly position the enemies on our map since the map is pretty big and I was too lazy to implement a mini-map I came up with a small game mechanic that would guide the player to their next Target the idea is pretty simple using the dot product of two vectors you can get an indication of the rate that the two vectors are pointing in the same direction I then find the closest enemy to the player and compare the vector pointing towards the player with the velocity Vector of the player a negative dot product will indicate that we are moving towards the target while a positive dot product means that we are moving away from it I can then simply map the result of the dot product onto the volume range of a Target computer sound effect to give an indication to the player if they are moving in the right direction it seems to work pretty well and I think it's actually more fun than just following around an error to your next Target the game is basically finished by now there is one last thing I want to talk about that helped me a lot to organize my code and deal with the switching of game States for example when moving from the main menu into the game game programming patterns is an awesome free resource to learn about useful coding patterns in the context of game development there is a write-up on the state pattern which I implemented for my use case I defined a state for each game scenario and then have an execution class handle the transition between these states the pattern gives you an easy way to define things that need to happen on entering or exiting a certain State although I said the game was finished there are many things that I would like to improve first and foremost I think what is really missing is the particle system for explosion effects that would probably be the one thing I would like to add apart from that there are many improvements that could be made especially in the code but this was more of a learning experience and one big goal was to finish the project which I did so I hope to improve upon these things in my next projects if you survive this far into the video I want to thank you for your attention if you liked what you see and would like to see more be sure to leave a like see you next time
Info
Channel: prjohdev
Views: 674
Rating: undefined out of 5
Keywords: dream game devlog, unity game, 3d game, how to make a game, making a 3d game, make a game, 3d game tutorial, game creator, game devlog, how to make a game from scratch, prjohdev, making a game in 48 hours, making a game in 24 hours, indie game devlog, simple directmedia layer, game jam sdl, learn sdl2 c++, indie gamedev, game jam, sdl2 game, c++ game dev, learning sdl2 in 48 hours, game dev, c++ game, game, discord, 48 hours, c++, I Created My Dream Game
Id: Fvi0mUBqppw
Channel Id: undefined
Length: 13min 5sec (785 seconds)
Published: Sat Mar 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.