Game Developer Makes a Mobile Game (1/4)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up guys Darren here with renaissance coders and i'm really excited to finally start this series as you may already know we are kicking off our one game a month challenge and then teaching you everything you need to know to make your own games and it really couldn't have come at a better time to when we're about to hit a million views on our flappy bird tutorial which is just insane to think about and I think it's just obvious that you guys would like to see more videos like this so I wanted to talk a little bit just for a moment about sort of salaries and game development you may be coming across this tutorial because you want to get into indie development or maybe you want to get a job in game development and so I thought it might interest you to preface this video with a few statistics from Glassdoor you can see here the average pay for a developer in the US is 50 grand ranging anywhere from 52 to 80 thousand I think that's a little bit on the low end based on my experience it's really easy for game developers who really know their stuff to hit six figures and there's actually another article here that I'll post in the description that you can take a look at this has a little bit more statistics on companies and different states in the US and you can see that a lot of these these top companies are actually paying a lot more than that average and you'll see that you'll even get well into the six-figure range here that might be in the the higher value states when it comes to cost of living like California or New York but you can still see that it's very easy to get into that six-figure range as a game developer so this is definitely a good time to start learning these skills and what I've learned with game development as well is when you when you become really good at creating game development software you become really good at software in general because game development requires it requires creativity and it requires technical expertise as well and so those skills translate across software as a whole so this is a really good industry to be getting into right so let's talk about what we're actually going to be making here and I do want to preface that all for all of the games that we're gonna be making this month we're actually going to be putting these on the Android store and later on the iOS store and they'll be available for you guys to actually download and play before you can get into the tutorial and you'll actually be able to you know play the thing that you're going to create and then of course if you guys want whatever you guys create from this tutorial you can feel free to put up on the store as well so the first game that we're making is called tap shift and let's just sort of go through it to see what is it what the game is all about okay so essentially you're just this little ball and you're bouncing up through these different obstacles the goal is to not get hit so when you get hit you actually lose and then you get this game over screen that gives you an overview of your stats for that that that round so you can see here we have the score displaying here under the star or the personal best you have the distance traveled the amount of currency that you may have collected and then some XP you have the ability to go back home or to actually restart that round so let's just play through for a little bit and and see what else there is so we actually have some some pickups in this as well see here's a times for multiplier for your score so now you can see every time we pass an obstacle we get four points then we also have this one which is pretty interesting the rotate pickup that actually rotates your screen and this gets long definitely a little bit tricky to play and then here we have an invincibility mode so those are our three different pickups that you can actually collect and you can see with invincibility mode you can just click right through without dying okay so they were picked up another camera rotation so that's the game it's really simple and it was actually inspired by a game called color switch which he may have heard of it has about 10 million downloads on the Google Play Store and that one's definitely different but it was inspired by that game as well as another game called duet which I'll link both of these games in the description if you want to check those out the the game that we're making is definitely different from both of those but you can see some similarities in in those when it comes to this game for instance color switch you have the same portrait view where you're clicking to progress through the level and then with with duet it's sort of this cool black and white aesthetic where you're also traversing through obstacles to make this game we're going to be using c-sharp and unity 3d and just to list a couple of the things you'll be learning throughout this series we have asset creation finding audio and sound effects for free for commercial use of course c-sharp game programming specifically you'll learn a lot about the unity 3d editor you'll learn about animation you'll learn how to use different tweening scripts you'll learn about physics triggers and camera manipulation just to name a few things the structure of this series will be like this it'll be split into four parts so I'm not sure yet how long each of those parts are going to be I think in total they should be less than four hours for sure so possibly 45 minutes to an hour per video the first tutorial that we're going to be going through today is going to cover sessions game controller player controller and the camera controller and the second video we're going to be looking at obstacles and the design of different obstacles we're going to be looking into pickups and creating some of the art for the pickups in part 3 we're going to be covering player death the game over screen and score tracking and to tie it all together in the fourth video we're going to be bringing together the splash screen with the main menu screen and adding some audio tracks to the background and that should add a nice polish to our game the end and after you go through each of these four parts you should have a pretty cool game developed that you can of course put on the the Android store for yourself or on the iOS store all right so hmm starting things off here we'll just open up the unity hub and we are gonna be using let's create a new project we're going to be using unity 2020 point 1 alpha and the current version that I'm on specifically is the alpha 17 I think they're on 24 or maybe beyond that at this point but whichever alpha version whichever alpha version you're using should be fine in fact using any version of unity you should be able to follow along 2019 or 2018 even 2017 you should be able to follow along there's nothing too crazy that we're doing here specific to 2020 okay we're gonna be building a 2d project so we'll select that and then we'll just call this tap shift demo and go ahead and choose a location that you want this to be in I'm going to choose mine right now and once you select your location you can just click create unity is going to do some setup here for the 2d project but it's all going to be very basic and I don't think there will be really anything in this project so we're really starting from scratch here okay so while this is loading here let's go over to github and I'll put a link to this get in the description we are going to be using these tools so do this right now go over to github go over to this link and clone or download if you're if you're comfortable with git you can go ahead and just clone it into your directory you can feel free to fork the directory and make any updates that you want in the future as well if you're not familiar you can just click download zip that's going to give you all of these scripts here and these scripts are of course subject to change over time but we are going to be using these in this tutorial so make sure you do this just go to download zip and then we're going to be pulling that code into our project so I think unity opened up so let's go over and see what our project looks like so far okay so they start us off with a scenes directory and the packages directory there's nothing in the packages and we have a sample scene we're going to delete because we want to start with our own scene from scratch now my layout might look a little bit different than yours feel free to adjust some of your windows as needed just a high-level overview for those of you who aren't too familiar we have our project directory which is going to hold our assets we have the hierarchy which is going to describe what we have in our scene and then we have the scene view which is where we can actually make modifications to our game scene there's nothing in there right now I'll stay in 2d mode for the rest of this tutorial and then we have the game view which is going to represent what our actual window is going to to show for the game what's actually going to be showing up on our mobile devices okay so we downloaded that zip let's open up the zip contents and see what we need to bring into our project before we do that let's create a new folder called scripts we'll open that up now let's go see what we unzipped let's see okay so in my downloads now I have unity core master I'm going to extract this and then in here we have some code I'm just going to grab all of these folders and drag them in to our actually before I do that let me create one more folder in here called core so in our scripts folder we create another folder called core and then and then I'm going to drag all of these into there okay and we might have some errors because these scripts are not totally dependent it looks like we're looking for a game controller which is no problem all we have to do is create that game controller actually what I might do instead is go to the session controller and make a couple updates real quick so whatever we went over the session controller in that tutorial yeah by the way it's worth mentioning that all of these scripts I just pulled in there are tutorials for each one of those in case you aren't familiar those will be in the description as well but we talked about in that tutorial making some connections to the game so I'm going to comment out some of these these calls to the game and then we're actually going to come back and go go back over the session controller script since it is relevant to this particular tutorial there's also some references to the page controller we won't worry about going over that just yet but that should clear up some of the errors that we have in unity so let's go back to unity and make sure everything is okay so instead of commenting out that I'll just comment out the entire function here okay let's get back to unity and then page type doesn't have a reference to pause pop-up so we'll comment out this line as well okay with that we have our course scripts just to go over a high-level overview we have a nice audio controller to help us manage our audio tracks we have a data controller to help us save and store any sort of game related data on the user's device we have a nice menu management system that we will be taking use of taking advantage of in this entire series and then we have a scene controller to help us switch scenes which we will be using a session controller which is pretty much already done for us but we may end up adding or modifying that and then we have some tween scripts that are going to help us move objects smoothly and reliably so we're going to go over a lot of these tween scripts for this particular game and will will either be talking about these in this tutorial or in part two of this series okay so we're off to a good start we have pulled in our course scripts now we need to make sure that we're actually in a Android environment so we want to go up to file and then go to build settings right now we're in the PC Mac and Linux standalone build settings we want to make sure they weren't Android and so if you've installed unity you would have been provided an option to download the Android tools if you haven't done that you want to make sure you go ahead and do that if you haven't installed the Android tools there should be a button here to allow you to download those and then unity will handle the rest for you now it's worth noting that whenever you go to publish you're going to want to build an app bundle and what else is different there's there's a couple things that are different with the Android requirements whenever you go to build you'll need to change your scripting back-end from mono to aisle to CPP and then you will be able to support arm 64 which is what you need to be able to support and so those are those are some settings that are a little bit different I know a couple years ago Android was was easier to deploy to but now you need to enable il-2 cpp and then you also need to be building the app bundle so you want to make sure that this check box is checked but once we do that let's go ahead and switch the platform and that might take a few seconds depending on what you were already having your project should be pretty quick for us because we only had it a few scripts after this finishes we'll go ahead and get started with our first scene in this tutorial we're going to just focus on the game scene we won't worry about switching from a splash screen to a menu screen and then playing the game we're going to start off really simple because the main thing that we want to do in this tutorial is simply have the ability to see our player and then click to move the player long and then we want to have the camera follow that player so those are the main requirements for this so let's start off by going to our scenes folder and creating a new scene and then we'll call this scene game very simple and before we forget oops I accidentally saved the scene that we were on I'll go ahead and delete that so before we forget let's go to our build settings again and then add the open scenes whenever we go to actually build the game whenever we actually go to build the game we're going to want to make sure that this scene is in our build so that that's actually what shows up on our device when we go to test okay I'll make sure everything you saved here so we have the game and we have a main camera in our game scene what I'm going to do is just set the background color to black since that's going to be the background color of our game now I would like to mention that while we're talking about how to make this game I highly encourage you to come up with your own designs come up with your own art don't just copy everything that I do come up with something that's original so that when you actually put it up on the store it's different from what I have and you can actually gain traction that way instead of just cloning games I come up with something that's a little bit unique to your own game same thing that whenever we go into talking about different pickups and what those pickups do try to think of different ways or different different properties that your pickups are going to have on your player don't necessarily copy exactly what I'm going to be doing but for me I'm going to set the the background to black okay our size is 5 our projection is orthographic which is fine and we have an audio listener on here so that's all fine so the default settings look okay for our camera okay so we need a player and we're going to start off simple here let's go to create 2d object create sprite and then let's see if we can find something default in here so we have a knob object so we don't need to worry about creating a circle or creating any art in this tutorial so our player is going to be this circle this knob and let's let's position the circle to where it's sort of in the starting position relative to our camera and that's going to be somewhere here I would say and the player probably needs to be a little bit bigger I'll go ahead and name the player I'll also tag the player with the default tag and here called player because I think we'll end up needing that eventually when we start dealing with triggers and physics okay so we can see the XY position of the camera is zero so we want to make the player relative to that so relative to the camera we want the X to be zero and then we just want to move the Y position down we can say two negative four that looks good and then we just want to increase the size of our player in general so I think a value of two for our player looks okay you can modify this if you want though you can make it bigger or smaller okay at this point we are ready to start creating the player controller and the camera controller so we're moving right along at a good pace here in our scripts folder I want to I want to organize this in a way to work our course scripts are dependent from the rest of the game as much as possible so with that being said we want to have a separate folder for our game scripts and what this has allows us what this allows us to do is say you know when we go to create another game we don't have to change anything in core or we have minimal changes to make in core from game to game and only our game scripts should be changing from game to game so we're going to create a game script in here we'll create one for game controller we'll just create everything that we're gonna use in this tutorial so we'll have the game controller we'll have the player controller which is what we're about to create and then we'll have the camera controller let's see if there's anything else that we'll need for this tutorial I think that's it we have the session the game the camera and the player so I think that's all we need to touch for part one okay so let's open up the player controller so let's just think about what the player needs to do remember the player is going to be this little white ball at the bottom of our screen that when you click or when you tap the player moves up incremental e and when you stop tapping the player falls down so there'll be some gravity manipulation in the script okay now let's go ahead and just start from a sort of blank slate and then add things as we need of course I like to organize my code with the regions so we'll add a region for the unity related functions and then we'll also add one for public I don't know if we'll need public functions yet but I'll add the the region anyway eventually we will need public functions we'll have some public functions for the game controller to utilize but I'm not sure if we'll need those just yet since we're only focusing on the player itself and how that player moves okay so for our public functions of course we'll have the for now we'll have the public I'm sorry the private start so we'll do some of this some initialization and start and then we'll have the update function of course to handle the player updates for public functions we won't worry about yet and for the private functions we'll have will have some functions to control or to sort of separate the actual actions that the player is going to to be able to do so for instance the player will definitely be able to jump so we'll add a jump function the player is definitely going to fall so we'll add the fall function and then we'll want another funky just to handle actually moving the player so actually moving the actual transform of the player we'll call this move so all of these functions will be called an update and we'll handle each one of those actions respectively within its own function so an update we're going to say we'll call jump then we'll call fall and then we'll call move and the order of these aren't necessarily to too important from what I've seen you can order these however you want since they're all become being called in the same frame okay let's talk about a couple of the member variables that we're going to need in the player controller we'll have a couple of public parameters that we can manipulate from the inspector the first one's going to be the actual smooth time of the player so how fast the player moves towards its target position will have a jump force so how fast or how with how much force does the player jump I'll have a float for the acceleration of gravity so how fast the player starts to move towards the bottom of the screen so have that as gravity acceleration then we'll have a maximum on that gravity so it doesn't get too out of hand and the player doesn't start falling too fast we'll have a will have a max on essentially the maximum force downward on the player so we'll call this max gravity okay we'll have a vector3 which is private for our target position so this is the position that we're trying to move the player towards at a rate of this smooth time we'll have a private float or the downward velocity so this is this is the velocity dictated by the gravity acceleration and max gravity so we can call this a downward acceleration and then we'll have another actually I think this is all we need I think this will be fine for now we'll come back and add things as we need to but I think for the minimum requirements of this player controller I think these are the only member variables that we're going to need so let's start off by by defining our move function because this is this is what actually moves the the players transform towards the target position and target position is just going to be be manipulated by jump and fall okay so move is going to be pretty simple it's going to be a one line function all we're going to do is be moving the players position so we can say transform which accesses the players object transform which has access to the position and rotation and scale so we can say transform that position is going to be equal to alert it's going to be equal to vector three larp and inside the lerp we have the initial value C the initial value that we're moving from we can say that that's transformed at position and that's okay and then our target position our target position is the the local variable the private variable for target position and then our third parameter is how fast we want to be moving towards that position with lerp it's it's technically a linear interpolation but what we're doing here is not linear however we can still use the lerp function with these parameters to add a smoothing effect so typically with this third parameter you would want a value from zero to one where zero which sets you equal to your first parameter and one would set you equal to your second parameter however because our our initial value is always equal to our current position we want a much higher value for our smooth time so the smooth time can be any value we want and doesn't have to be a value from zero to one necessarily so our third parameter you can think of as a speed so how fast do we want to move towards our target position and what we can put here is our smooth public parameter times time.deltatime and that's going to make this operation frame independent meaning the speed of the player should not be dependent on our frame rate okay so all we need to remove now in in the jump and fall functions we're going to be manipulating the target position so let's start off with jump so it's jump we want to check whenever the player taps or clicks so we can use if input dot get mouse button up and this being a value of zero or one where zero is your left-click and one would be your right click so when we when we get this operation when we get this input get mouse button up this will give us clicks on our PC and it will give us taps on our phone so this works pretty nicely for testing so whenever the player taps or whenever the players mouse button is up or whenever the player releases their finger on their mobile device we want to manipulate the target position and so the target position is going to be modified on the y-axis because we're working on the XY axis we're moving on the XY axis or the XY plane in this game so we want to modify in the up direction so we can say the target position dot Y is simply equal to the current position transformed out position dot y plus the jump force this is a very basic way to handle this type of logic we don't need to worry about using any sort of physics it's not necessary for this level of I guess detail this game is very simple so we don't need to be worrying about things like that or over complicating this operation we can simply add to the current position using this jump force this jump force parameter okay and whenever we do this we want to reset the downward velocity so we're essentially zeroing out the the gravity on our player so we can say the downward acceleration is now equal to zero which would imply that our fall operation is going to be manipulating this downward acceleration so let's see what we need to do there okay so the first thing we do in our fall method is modify the down or acceleration we can say the downward acceleration is going to be added by the gravity acceleration okay and maybe a better name for this would just be the downward velocity since this isn't technically going to be an acceleration variable the acceleration should modify the velocity so let's rename this to downward velocity that might that might make a little bit more sense okay so our downward velocity is going to be modified by modified by the acceleration and then we can say that we want to clamp that by the current downward velocity and the maximum gravity so we can say the downward velocity is equal to a clamp of the current value and I'm sorry of so the first parameter is the value that we want to clamp the second parameter is the minimum of course the minimum should be zero and the maximum would be our max gravity our max gravity public parameter okay so here we're adding to the velocity using gravity acceleration and then we're clamping the velocity to our our maximum gravity so hopefully that makes sense the next thing we want to do is of course modify the target position on the y axis so we can say the target position dot y the target position dot Y is going to be subtracted so we're going to subtract the velocity from the Y position so that the player moves in the downward direction so say the tark position dot y - equals the actual velocity so the velocity times time Delta time so that we can make that independent of framerate okay after we do that we just want to make sure that the player's position is never less than zero if the players position is less than zero then we want to actually not necessarily zero let's go back to unity and see what our minimum player position would be okay so what we're trying to do with this last part of this script is make sure that our player never falls below this point so let's see here so the players current position is negative four so we just want to say that if the players position is less than negative four then we set the player position to negative four this means that whenever we start the game and we start clicking the player won't die if they fall back down to this initial position okay however if the camera moves upward and then the player falls down off the screen and the position is greater than negative four then the player would lose because the players already made some progress at that point but whenever the player doesn't make any progress we don't want to penalize or make the player lose just because they fall back to their initial position so let's go back to the script and make sure that we're clamping the minimum to negative four okay so what this is going to look like as we'll say the target will use a condition if the target position dot Y is less than negative four then we just set the target position to negative four okay and that's pretty much all we need for the player controller let's go back to unity and see if this works so we'll click on the player here and we'll add the player controller of course we're going to have quite a bit of adjustment to do with each one of these variables I'm not exactly sure which values we want for these we'll start off small so the player doesn't fly off the screen we'll set the smooth to something like 8 the acceleration may be 0.1 and the max gravity 1 let's see what we get with those values I'm sure we'll have to spend a little bit of time modifying this though okay let's turn off the maximize on play so we can get a scene level view of what's going on so if I click nothing is happening maybe the jump force needs to be a bit higher let's say 50 200 okay so it looks like the player isn't moving one thing that we could do is add some logging to make sure that what's actually make sure that we're actually introducing the logic that we wrote for those functions so let's go back let's go back to the script and make sure that we have everything written correctly okay so what I'll do is I'll add a log statement right here just outputting the player's position so I'll just log the position I want to make sure that you know something is actually changing on the y-axis at least let's go back to unity and see if we're getting anything from this value okay and just to exaggerate this I'll make the jump force you know 500 or something like that okay so the player's position is definitely changing here okay so now it looks like you know if the jump force is that high or we're definitely modifying the player position so let's just reduce that back down to like 5 4 maybe for whatever reason my input wasn't being logged there we go for whatever reason the first time I was running that my my input wasn't being registered for my click but everything looks ok now of course the values need to be tweaked a little bit so let's increase there's a couple things we can do so the the gravity acceleration dictates how fast the player moves towards the maximum so that value might be okay you might just want to increase the max gravity so if I increase that's a 10 you can see we sort of we do we do approach the maximum pretty quickly and the maximum brings us down a lot faster let's let's see if we increase that max gravity further okay so not a lot of difference there we'll bring that back down to 10 or we can see what 5 looks like ok so I do like I do like watching the the player move down that fast that's a pretty good value but we need to maybe adjust our our force on our jump let's bring that back down to two okay so that actually feels pretty good I'm pretty pleased with that now one thing you want to do is is make sure you just you know tap for a minute or so to make sure that the player is moving reliably at all times you don't want it to be where you're you click you know 10 or 20 times and sometimes the player like flies off the screen but other times the player doesn't move up that much that would indicate you have some other underlying issue with how you're processing the player's position but this feels pretty good I'm pretty happy with this I'm pretty happy that we found those values that fast so if you want to copy my values I have the smooth at 8 the jump 4 set to the gravity acceleration at 1 and the max gravity at 10 and since we're in plane mode I want to make sure that I copy the component because when we exit play mode those values will change so outside of play mode I can right click on the component and paste those values back so I'll run the game again to make sure that everything still feels good and I'm pretty happy with how that feels ok so there's something that I noticed here when I start the game my player starts off towards the middle of the screen that's because our target position is initialized to the vector of zero zero zero so because our player is currently at a value of negative 4 we want to make sure that we initialize the target position where we want the player to start so let's go back to the script and do that so all that means is from our start function we want to say that the target position is equal to our current position just like that let's go back to unity make sure that the player starts off at negative 4 okay so everything looks good there and as you can see because because the player reaches negative four we never go below that value okay and you also want to make sure that whenever we approach this negative four position you wait a little bit and then click again and everything still feels good so you don't want it to be a situation where when you click for the first time the player doesn't jump as high that would indicate that maybe you're not resetting your gravity properly but this feels good this this thing this is a good start I think we might end up changing some of the values as we move forward okay so of course now we have an issue to where the player can just jump off screen and the camera isn't following the player so that's gonna be an issue so let's go ahead and get started on our camera controller okay so the type of behavior that we would want on our camera is whenever the player reaches a certain difference with the the the cameras position for instance if our camera is at zero and our player is within two points of the camera then we start following the player and that value can be modified so we can say if the player is it is within one point of the camera or if the player is one point past the camera then we start following the players position so that's kind of the behavior that we want I think what we'll do is when the player reaches right whenever the player starts going above the cameras position then the camera starts following the player so that's the kind of behavior that we're gonna try to strive for here so of course I'll start off by clearing out some of this boilerplate that unity adds for us and then I'll add some of our own boilerplate which is going to be the regions so I add a region for unity functions and then a region for public and a region for private okay from here of course we want to start adding some of our public and private member variables and because this is a camera controller I want to make sure that we're requiring that whatever object this is placed on has a camera so I'll add the require component attribute and we want a component that is of type camera and that's going to promise us that we'll always have a reference to a camera so we could start off by creating a reference private reference to our camera like this and then in our awake or start function we can initialize that reference so we can say the camera is going to be equal to get component camera and we know that this is always going to return a value that we care about because we're requiring the component of type camera so this should never be null okay let's go back to some of our public and private member variables and see what we're going to need here we'll need a reference to the players transform so we'll have public transform player will have a smoothing value so how fast do we want to move towards the player and then we'll have some private member variables down here we'll have the target position so we'll have a reference to the position that we want the camera to move towards then we'll have the initial position so where we want the player where we want the camera to start essentially so we can have that initial position okay eventually we'll have some controls in here to handle that pickup that rotates the camera so we'll end up having controls in here to change the camera size and rotation but we're not gonna worry about that right now we're just going to focus on being able to follow the player in a in an upward fashion okay with that being said these are all of the member variables that we're going to for now okay so in our unity functions will have an update so we'll say privately update and then we'll have a function called follow player in here so I'll go ahead and have that in the update function and in private we'll add the follow player function okay before we actually do anything in this function let's just do a little bit of housekeeping and so we want to make sure that the player reference actually exists so we can say you know if the player is null then we want to log a warning because if the player if the transform is null then we're just going to keep throwing errors in this update function which is not the behavior that we want so we'll log a warning and we'll just say camera could not find a reference to the player and then we'll return so we don't want to do anything with the player object if it doesn't exist okay from here we just want to see you know we want to get that value that difference value before we start following the player so we want to determine how far away the player needs to be from the camera before the camera starts moving so as I said I want to wait until the player moves past the cameras position so one thing that we can do to enforce that rule is say if the player not transformed that position is greater than the cameras position so greater than this position the transform tothe position Y so if the player is ahead of the camera then we start modifying the target position so we can say the target position at that point target position dot Y is equal to the player's position dot Y so this is a very simple way to do this all we're doing is saying all we're doing to dictate the follow functionality is setting our target position to our player's position so pretty simple there from here all we need to do is use a vector3 lerp similar to how we did in the player controller to actually move towards the players position so we can say transform da position is equal to vector $3 where the first parameter is our initial parameter or our current position so we can say the transform from the transform position towards our target position at a rate of smooth times time.deltatime and with that I think we should be able to go back to unity and everything you should be working pretty smoothly okay we do have an error here probably just a typo on my part the operator can't be applied to vector3 and float let's check that out so I need to be accessing the y-axis on the players position not just the player's position in general obviously that wouldn't be a fair comparison let's go back to unity and make sure that cleared things up okay everything looks good I still have some logs in the player function so are the player script so I want to go back to that and remove those logs because they're just cluttering up my console so I'll come over here and just get rid of this debug log statement there we go and then back to unity we go alright so on them on the main camera we want to add the camera controller and then of course we want to add the player and a smooth time let's just say a smooth time of 5 and see how that feels okay and we should let's see from our scene view as I start moving we should be able to watch this camera move up to follow our players position okay perfect and for some reason I can't see my player that's kind of weird ah okay well that's kind of interesting my my Z position on my camera is going kind of crazy never seen that before it's still at zero it's just kind of moving around my player is not in view so I will say that if you're using the alpha version of unity you'll see some weird stuff like this happen occasionally but just to be safe let me turn off let me remove the camera controller if I remove the camera controller and I can still see the player which I can then there's something with my player controller that's causing issues right there's something wrong with my camera controller that's causing issues which is kind of strange we'll see if we can figure this out without wasting too much time right so I think I see the issue here our Z position is being set to zero that's because I forgot to set my initial position parameter let's go back to the script and see what we need to fix to fix this little bug but before we do that you can see sort of how I found that out the the cameras position starts off at negative 10 if we move that toward zero then we get to the point where we stop seeing the actual player object if I go back into 3d mode here it actually makes sense because as we watch the camera move towards the player it disappears you can see it the point where it disappears is whenever it goes outside of the cameras viewing angle okay so that makes perfect sense why that was happening I'll move that back to negative 10 let's go back to the camera controller to see what we need to fix okay so from the start function let's first make sure that we're we're initializing our target position equal to the Train transform position same thing that we had to do in the player controller and then also let's go ahead and make sure that we set our initial position we'll end up needing this whenever we whenever we reset the camera during a game reset or game over so we'll go ahead and initialize set the initial position to the target position okay with that we should be good we can go back to unity and we should be able to see the player okay and just as an overview we have the camp controller on the camera and the smoothing set to 5:00 now we should be able to run this and watch the camera actually follow the player so you can't really tell in the game view but you can tell in the scene view now the interesting thing to note about this is when the player falls off of the screen the camera doesn't necessarily follow we don't really want the camera to follow in that case we would say that when the player falls off of the screen then we end the game however the only time that we move the camera is whenever the player actually moves beyond the cameras position so we'll run that again to dim and demonstrate that okay so you can see the camera follows but if we fall below the cameras viewing angle and the players position isn't negative for then we actually want to end the game so if we were to fall like down to here the player would be killed and we would show the game over screen okay so the last thing that I want to do in this tutorial is sort of tie everything together in a cohesive manner that is to say that we want the session to be in control of our game loop and we want to have a game controller that has control over all of the update loops related to our game so what that means is we're going to have this overarching session controller that manages everything about the app the session will have a the session will have a reference to the game controller and we'll always be in control of updating or not updating the game the game controller will have a reference to anything game related and how those things update so let's go to our scripts and make some modifications so that hopefully this makes a a bit more more since so I want to open up my core session controller here now you can see that in the beginning of the video we did comment some of the game controller related logic out i want to uncomment that stuff so our session controller will have a reference to our game and let's see we have the update function so the game will always be in control or the session will always be in control of how the game updates and we have that control through this paused variable which we may end up using later in this series the session is going to have a public function for the the game to access to initialize the actual game and when that happens we'll initialize the game and have a reference to our game to use in our update function so one thing that I want to make sure that I do in addition to checking for whether the game is paused or not is to make sure that I have a valid reference to my game before trying to update it so I'll say if the game is null then I also want to return here so make sure that you add that line in before making any of these modifications ok so with this that would imply that our game controller needs to call initialize game at some point it also needs a function called an update and on an it so let's go to our game controller and we're getting rid of some of the boilerplate here ok so one thing first of all is that we're going to have a reference to unity core does session that's going to provide us the ability to have a reference to our session our session controller so we can create that private reference and then the good practice to do with any sort of controller is to get that controller with integrity so what I usually do is I'll say throughout this script if I want to reference the session then I'll access it through a property a local property so I want to get the session with some amount of integrity like this so I'll say private session controller session and what this will do is I'll have a git er in here and I'll say if the session is no so if session is known then I'll say debug log warning and then in that warning I'll tell the developer that the game is trying to access the session but no instance of session controller was found and this is just this is sort of I don't want to say boilerplate but this is this is pretty common whenever you're trying to access a controller you want to make sure that when every time you access that controller if the session doesn't exist you want to log the warning in return will return null or actually we don't need to return anything here the the property is always going to return the session Knowle or not it's the caller's responsibility to determine what to do if the session is null and I'll show an example of that in just a moment the first thing that we do actually is if the session is null then we set the session so we say the session at this point would be equal to session controller instance if we go back to our session controller you can see that we have this static access err for the instance okay so let's go over this really quick if the session doesn't exist we initialize the session if after we initialize the session the session still does not exist then we want to log this warning regardless we're gonna return the session okay so we'll see how to properly use this property throughout our game controller in just a second okay I want to add some boilerplate here we'll have the Unity functions the public functions and the private functions so I have public and private down here okay so for our our unity functions here we're gonna have the we'll have private let's see let's just do a weight or let's do start so we want to do this and start then we'll say if not session then return okay so what this does is it calls all of this code and the getter for us because we're accessing the session so if not session returned if we get beyond this statement this condition that we know that we have a valid session and if not then we we log that warning for the developer to see so here I would say session initialize initialize game with this okay so remember the session controller is going to call game on an it and game on update so in our public functions we want to we want to create those those definitions so we'll have a public void on an it and public void on update so notice that we're not doing anything in the update function on the game controller in other words we're not calling update like this the reason why is because we want all of that localized we want all of the update localized to the session we also want all of the initialization localized to the session so in essence the session has full control over everything about the game so an on an it we initialize all of our game systems and in on update we update all of our game systems okay so what this means is our game controller is going to have a reference public reference to our player controller and our camera controller okay and what we'll end up doing is saying player dot on an it camera a dot on an it and same thing for updates so a couple of benefits here one benefit is you get a nice high-level overview of everything about your game from initially from initialization to updating the second benefit is you have control over the order you have direct control over the the order of how things are initialized and how things are updated which can be very valuable at times okay so what this implies of course is we need to make some some modifications to our player and our camera controller so let's go to our player controller and instead of this private void update and this private void start we're going to move these over to our public functions and call this on an it and on update just like that okay and we can probably get rid of this region we might end up requiring to to do some things and some other unity event functions later if we need to then we'll add that region back okay and in our camera controller will do something very similar of course we'll take everything in start and update and move those into and on an it and on update function okay so that looks like about all we need we do want to make sure that while we're testing here the paused variable is going to be false which I think it should be so let's just go back to unity and hook some of the stuff up and see if it works okay so we do have some errors here I may have forgotten to make these public so we'll go back to our player and our camera make sure that those update and initialize functions are public and then let's go back to unity to make sure we fix that okay so everything looks good there we're going to have an empty object for our our core systems okay so our core systems are our our persistent systems that'll include our sessions are audio management our our menu management and other things like that so we'll have on our core system object the session controller and on we'll have another empty object called game systems and on our game systems we'll have game related systems of course the first one of which will be the game controller so the game controller will need so far a reference to the player and the camera and with that we should we should be able to play the game and everything should work exactly the same okay so everything is exactly the same but we have the benefits of the things that I just talked about okay and so with that I'm going to close out this tutorial we are at a very good point where we have the the session and the game relationship tied up nicely we have player movement and camera movement and in the next tutorial we're going to be covering the the creation of obstacles and the spawning of those obstacles the design of various different types of obstacles and then we'll also start introducing pickups and the scripts required to implement those different pickups so thanks for watching part one of this series we have three more parts before we finish the game and then of course we're going to be continuing this throughout the year with ten other games so thanks so much guys for watching leave a like and subscribe turn on notifications and refer this to a friend who's trying to get into game development so thanks guys and I'll see you in the next tutorial
Info
Channel: Renaissance Coders
Views: 8,670
Rating: undefined out of 5
Keywords: unity3d, unity 3d, flappy bird, tutorial, c# game tutorial, c# game, how to make your own game, unity 2d tutorial, unity3d developer, unity game design, unity game developer, unity development, unity programming, unity game development, unity android, unity for app development, unity app development, unity android app, unity mobile app, android unity, unity tutorials, how to develop an app, how to create an app, how to make a video game, parallax, unity 2020
Id: 0HKUonMnUfE
Channel Id: undefined
Length: 61min 47sec (3707 seconds)
Published: Sat Feb 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.