Building a Multiplayer Game LIVE - Finished Shooter

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right hello everybody hopefully everyone can hear me and everything looks good i did a little bit of testing i'll put the light back on brighten it up a little bit um today we're gonna go through building a multiplayer game i'm gonna continue on from the project that i started with the last stream but i'm gonna really quickly run through it so that anybody who didn't see that can understand what the starting point is what it looks like and how the code works it's not very complicated but i think it's worth a just a real quick like three or five minute recap show everybody what we're starting with and what we're going to turn into multiplayer and then uh yeah i'll talk more about it let me take a drink hit play and uh let's see the game in action first so the game that we built in the in the last stream that i went through building is just this little uh third person shooter where you can run around with wasd and you can use the uh the mouse to aim everything sounding good to make sure that everything's still sounding good out there um so you can run around kill the robots and get some points a bunch of different robots spawn and you can keep track of the high score there's a high score right up there of what is it 7 500 let's see if i can beat it real quick give me a second give everybody a chance to get in oh i don't know if i'm gonna live kind of what behind the text can i beat 7 500 probably not oh there we go 9 000. so you see if i stop playing now and play again we save off that high score let's see there it is there's the high score so let's take a real quick look at the project right now what it looks like um how it's all put together and then we'll go through how to turn it into a multiplayer game where we have two players running around shooting keeping track of scores and competing maybe add some goals and just keep building on some really cool features i'll try to explain it all as i go along so you can kind of follow along also if you want the code that i'm going to go over there's a link in the description you can just go grab it it's at a game dot courses slash 3d dash shooter i probably should have got rid of the dash there but if you go to that page um you'll be able to just grab the source code and follow along i can't give away the art because it's from some asset packs but you can grab the art yourself or get whatever art you want and use the same code it's going to work exactly the same the process isn't any different all right let's take a look at the project now so the first thing we got in here is the actual player this was the dude that was moving around and it's this robot soldier that came from an asset pack that i pulled in it's got a rigid body on it a capsule collider and then it has two scripts on it for moving around it's got that player script that moves it using wasd and then it has a gun to do some shooting and the aiming let's take a real quick look at the player script oh here we are we're in oh well hold on i'm not showing my top oh sorry okay we'll start that over let's go back to what the game actually looks like not just me blabbing about it okay good stuff okay sorry about that everybody all right so here it is in the actual game with me running around and shooting and blowing stuff up so you can see my score you can see it going up as i blow up robots and you'll see that i'm not probably gonna beat that high score of ten thousand this time last time it was seven thousand i uh well beat it oh maybe i will let's see i'll keep trying and see if i can beat beat my high score in this game this little marvin robot's worth a lot more points than everybody else so gotta shoot a couple more of them come on there we go now i broke the high score if i stop playing and play again you'll see that it starts showing up again okay there we go hopefully everybody everybody's seeing it now right so you see the new highest score is showing up so let's take a look again at what the assets or what the project looks like and what the actual character looks like how it's set up and then look at the code so here's the soldier again this is our first player the one i was just talking about it's got an animator that's doing the little running animation and it also does an idle animation when we stop playing here let's take a real quick look so if i am not moving around like he's kind of stands still and shoots and if i run he's plays a little run that's the animator doing that we've got a rigid body controlling the movement or controlling the physics interaction with the movement it's primarily therefore handling collisions because we need to handle collisions when we get hit by an enemy and die in fact i don't think i showed that if i play and if i die you'll see that the game just resets and already we're going to see this code in just a second so you know exactly how it works there we go you saw it died at reset let's go look at the player again the other thing it's got capsule collider for handling the collisions and then it's got the player script and the gun script player one again is for moving around and the gun is for aiming and shooting so let's look at the player script will open up and here you can see we've got a script that's a inheriting from mono behavior so it can be a component it's got two serialized fields for speed and the direction i'll talk about the direction one in a second speed is a pretty straightforward and obvious one though it's effectively how fast the character moves we turn it up while we're playing he'll move faster let's scroll down a bit more so i've also got in here an animator that we're caching oh i went right past it that's the one that we're using to control whether he runs or walks and you see that line down here on 21 and then here we read the horizontal and vertical input we move the character based on that input by creating a vector using the horizontal and vertical and ignoring the y because we don't want to go up and down and we're just using transform.translate to move it now the one thing that i talked about that was a little bit or said i would talk about a little bit different is this direction here this transform object the reason that we're using that and the way that it works is here let's delete this comma and re-add it so we get the intellisense oh let's do it so it's not behind my head there we go so you see that if i add a comma one of the optional methods for optional ways to call translate is to pass in a transform to move relative to so you'll move relative to its orientation and if we go back into the game i see that my player is referencing this direction object right here it's placed in the scene if i go to it i'll go hit f over the scene view see this is actually oriented just like my camera but with the y or only on the y so it's oriented and turning and if i want i can adjust this at run time to completely can adjust the way that my player input moves i can flip it around or whatever else i want to do all right we'll go back into the gun script because that does the movement and then um i think we'll just get into writing some code start making the movement multiplayer because i'm talking a lot and not writing a lot of code i want to get to writing code really quick so first let's look at how the movement works so the movement system or the not the movement the aiming the aiming part of the movement is all done in the gun right now and that's because we needed the direction to determine which way to shoot so we do it by creating a ray using the camera main screen point to raise just getting a ray in from the camera over where our mouse is and then doing a raycast into the world so we're essentially seeing where the mouse is in the world what position of terrain the mouse is over we get that point back and we get that back in this uh hit info object or this raycast hit which is a i think it's actually a raycast hit object the default name for it a lot of time is hit info but here it's named raycast it so we get the point where we hit on the ground we get the direction there to that point and then we turn ourselves in that direction by setting transform.forward to that direction and here on line 21 we're just flattening it out after that we deal with shooting which is essentially just looking to see if we're ready to shoot can shoot just says hey if our time is greater than the next time we should shoot then do our shooting and the shooting goes through a relatively simple pooling system i don't want to dive into a full review of that code though so let's get into making it so we can move two players around make our player script multiplayer and we'll we'll start with some really simple stuff i've got a sec or i use no i lied first i'm going to make it so that we don't use the mouse because the more i think about it if i want to make it multiplayer and the first version of multiplayer i want to do is just with two controllers then i want to get like two controllers on my arcade cabinet and then make it networked multiplayer after see how far we get with that but i want to start with just two playstation controllers because it's going to be the easiest way to go and then we'll get our project started to be set up for more multiplayer separation so the the first step is going to be making it just work for two different players i got two controllers here i need to update my player script and my gun script so that i can move around with these but i also need to get rid of the mouse input because if i need to aim with my mouse like i have it now let's just go see it real quick for anybody who's not sure what i'm talking about right now the aiming is based on where i'm pointing the mouse and that's obviously not going to work for two players i could maybe have one player use this the mouse and keyboard and one use the controller but i think i'm going to set it up to just use two controllers because i think that'll be better when i switch it over to an arcade cabinet and um i wish i could turn my camera easily but i got the cabinet set up over there with just two little controllers and thinking you use one to move around and one to aim so just kind of map that right here and then again after that we can just switch it out to network multiplayer um once we get it uh actually working as a local multiplayer first all right so let's get going with um with the code for this so what would we need to do well first we'll go into our gun script and let's make it so that our gun script no longer aims the character i'm gonna move this to its own script or maybe into the player script kind of up in the air and about it or up in the air about it so i'm thinking maybe i'll just put it on its own script and then maybe merge it actually no i'm just going to move it to the player script so what i'm going to do here is take all of the code that does the directional stuff the part in my gun let's zoom out a bunch you can see the entire script so here you'll see that in the update we check to do some aiming and then we check to do some shooting and then all of this stuff is related to shooting in fact i could see that even better if i take this part doing the raycast and i just added a method so i hit extract method and i selected the whole chunk of code let's zoom this in a little bit and make sure it's obvious select this whole chunk of code hit alt enter hit extract method and call this um aim towards mouse i've got a method that handles aiming towards the mouse and another one that handles shooting and now i know that hey this junker code really doesn't necessarily need to be in the gun and could probably be in its own class and the reason i want to separate it out is because then when i do it like this i can see hey is there anything else that doesn't count in there and i don't see anything but let's move it and see what happens i'll take this chunk of code this aim towards mouse i'm going to go up here create a new class and zoom in a bunch make it a public class and let's call it aim towards mouse or let's call it controller aim i like that better because it's a controller based aiming system we'll use it make it a mono behavior so it can be a component and then i'll paste in that method the aim towards mouth method delete out the private keyword because i don't need it and then here i've got the first little error so the first thing i'm going to notice is that direction doesn't exist so i need to fix that and make some sort of a direction but really when i think about it i might not even need to cache this direction so i could probably just say var direction equals that um the other thing i'm going to need is well do i need the shoot point yeah i'm gonna need the shoot point so i'm gonna have to take oh let's see do i want to do it that way then let's see that's gonna get me my direction from the yeah let's do it we'll move move the shoot point onto the controller aim here in fact i'm starting to think this might go more over to the player and then um let's see does this need to shoot point two the shoot point is needed on here too i'm gonna move the shooting point to the player so i'm gonna cut that since i need it in both of these scripts and they both need a player i'm going to just put it onto the player and again i might end up just moving some of this stuff over to the player so this shoot point by the way for anybody who hasn't seen the previous one is actually just a child object down here if i expand it out here i'm going to hit alt and click to expand everything and if i look down here i think it was under the right hand there it is this shoot point object or transform child and it's underneath the rig for the animation so if i zoom in here if i hit play i'm just going to let it play first oh i've got an error i gotta fix i'll let it play but you'll see what happens is this essentially follows the tip of the gun it's a point for us to shoot out of we don't use the rotation on it just the um the actual position of it so that it shoots kind of from the gun so we get the full looking effect oh let's go back fix the code and then we'll show that in action in a minute so we've got our shoot point moved over to the player and then i need to make sure that this is accessible from my gun and my other script so i'll make this a or i'll make a public property that wraps it so say public transform shoot point and i'll just make it return back shoot point just using an expression body public property so this is the same as writing it like this get return this that so i could write um write it right public transform get oh i missed see i already i missed a brace here there we go i put it in the wrong spot the same as writing it like that but just much shorter to use the expression body method or expression body property that's my preferred method now so there we go we've got a publicly accessible shoot point that can only be set in the inspector it can't be modified it could technically be set on the player too but nothing outside of it can modify it so if i go back over to my gun this can now reference my player's shoot point position so i'll say underscore player dot shoot point dot position and then down here i'm going to do the same player doesn't exist on these we're going to create it in just a second so i'm going to get rid of this aim towards mouse on the gun script zoom down here actually let's just zoom out a bunch so you can see the both of these scripts and i'm going to move controller aim to its own file so if you just click on the class name and zoom in click on the class name alt enter and hit move to file there we go to the third one there if you hit the top one you might end up moving at the wrong place so make sure you look and click on the right thing so move it to its own file and then let's zoom out a little bit again and let's fix the issues here so this gun is still referencing the shoot point and that's just to get the bullets rotation and really i don't think that well do i need the shoot points rotation here i guess i do right because i'm using it to i probably don't need it for the rotation but i do need it for the position i'm going to make this be underscore player dot shoot point i'm going to scroll this up and zoom it in again so make it underscore player dot shoot point and we'll do the same thing here underscore player dot shoot point now i'm gonna fix that right in these two spots and then we're gonna go actually make the player because the player doesn't exist and this seems a little bit confusing i'm making essentially making a reference to this shoot point on the player it's usable by both of these other scripts so i have my gun script and my controller aim script if i hit controller and control comma by the way to bring this little search up both of these need to get this shoot point from the player first i'll fix it in controller aim and then we'll go back to the gun and fix it so to fix it in controller aim i can just add an awake and then i'm going to shorten this up watch this we'll shrink it way down it'll make it an expression body method and we'll say underscore player equals get component layer add some braces or our parentheses and then we'll generate a field for players so click on it alt enter and generate a variable get that i'll double click on private and delete it too all right so now we've got a player here and all we need to do is make this update or did this get called during the update in that case since we're only doing one thing i'm just going to replace aim towards mouse with update so it gets called every frame and save that off i think that fixes our controller name so now our controller aim will reference a player and it will reference the shoot point on there in fact since our controller aim always needs a player i'm going to add the require component attribute here and we use the type of and give it type of player this will do is just make it so that controller aim requires a player it won't work it won't let you add it to the script or to an object without a player if you try to it'll actually add a player automatically all right so that will fix that issue up and then we'll go into our gun and we'll fix it here so same thing here actually let's go to controller aim i'll just copy this copy these two lines and go to gun go up to the top and i'll just paste them in right here we've got another field right after our pool for our player and then we've got the awakening get rid of that extra space there that extra space and that one i'm gonna zoom out a little bit make sure everything's updated okay all right so let's see anything going on sorry i have not i've been trying to keep an eye on stuff but uh chat's uh hopefully i didn't miss anything too important there um for anybody asking if this will be available after yeah it'll still be there um you'll be able to go back through re-watch it follow along and stuff and i'll post the updated code too the current code i'm using as a starting base is right down below you can just go grab it copy it out of the gist or something and um start playing along yourself all right so we've got our scripts both updated i've got my controller aim updated i'm going to go double check that it works and then we're going to make it actually be a controller name because right now i had named it controller aim but that's really a lie this is a mouse name so we're gonna we've got the code moved out we're gonna add it on here and then we'll fix it up let's go to our robot soldier now that it's extracted and added if i hit play now i expect that i can't turn around right i shouldn't be able to turn if i can turn then yeah it would mean that my gun script wasn't updated so let's add the controller aim now i should be able to spin around with the mouse and then we'll go change it to be an actual controller and let's see oh what oh i'm not actually hitting oh okay there's an issue the problem here if you look down at the log is that i didn't assign the shoot point this happens all the time i moved the reference from the gun to the player which breaks the reference so i just need to go find the shoot point here i've got the player selected i've got the shoot point right there available to drag and just click drag don't release until i get on it and then release save and play and now i expect to be able to turn around there we go now i can spin my bullets um are not firing i think that's because i'm not using the rotation but we'll figure that out in a second for now let's get the controllers moving i don't really care about the bullets until i get the controller part moving and working so i'm right now turning with the mouse and i want to be able to turn with the thumbstick i'm also only moving with wasd let's go hit play and see if i can move with some stick at all if it works or not if i hit play got my thumb sticker i can go left and right i cannot go up and down if i hit this other thumbstick it doesn't do anything and there we go i died so i need to first fix moving i'm going to fix that on this controller and then we'll set it up for our next controller so let's stop playing and we'll go into our robot and let's go to the player script and right now the player script is reading our horizontal and vertical axes and these are set up if we remember it's in edit project settings and input manager and then here we have a horizontal and vertical these are for the keyboard this is reading left right or wasd here you see left and right there or a and d or horizontal and then is uh w and s and then up and down so those aren't the ones that we we want to use but those are the ones that i'm using right now to move around the ones i want to use for the controller down here they're horizontal that's like halfway down there's this one that's set up to joystick axis x and it's set up to read from all joysticks so theoretically it should move horizontal on any joystick and then there's the vertical one which is set up to y on all joysticks so the problem here is that with playstation controllers and i don't know if it's just my setup or all of them i assume it's all of them and the default here we need to change this to third axis and i can it might change in different unity versions too i'm not completely sure but for this case i need to switch this over to the third axis instead of the y axis if i hit play now i should be able to move around with this controller let's see click in the game view there we go now i can move around with it and i have this other controller i can actually move around with either one of them so that's kind of working but now i want to switch it up so that i can only move with one controller and then i also want to add in an aiming with one controller so i'm going to add in a new axis here and the reason i'm doing the movement first is because i'm going to need to add in an axis for both players and i'm also going to need to add in a movement an aiming axis for both players and a moving axis for both players so i'm just going to start by creating the first one as a moving axis for both players and then we'll make the aiming one and fix up our spinning around part i guess so the first one is going to be a horizontal but for just player one so i'll change this over to be just joystick one and i'm just gonna add the number one at the end of it i'm gonna do the same with the vertical i'll change this to vertical one and change this to read from joystick one only and then i'm gonna collapse these down so that you can see them all and right click on horizontal one and hit duplicate array element i'll rename this to horizontal two and change this to joystick view collapse that down and duplicate this vertical make vertical one into vertical two and switch it to joystick two i should have two different axes reading from the different joysticks i move this just kind of out of the way or something and hit play my controllers shouldn't work i should no longer um be able to move around the reason for that is that i got rid of horizontal that was reading from the joystick yeah i did i just wanted to double check i got rid of the horizontal and vertical that we're reading from the joystick and i renamed them to horizontal and vertical one and two so i need to go update the code to make that work so do that i could just go in here and say hey horizontal one and vertical one right but then this would only work for one player so i need to make it work for multiple players i'm going to change this to be instead of a number here plus underscore player number and i'll copy that and paste it right here then i'll generate a field for it alt enter and generate a field and i'm going to make this an int make it a serialized field and i think i'll just default it to one so that by default the player is controlled as player one and we'll move it up here to the top there we go we've got a player number that is now used to read the axis go back into unity and i'm gonna go collapse everything and just disable my spawners so those robots don't come murder me there we go save them off let's hit play and see if i can move around with a controller now all right so i'm in i cannot move with this controller let's try this other controller i can move with this controller if i click on my player and i change this to player number two let's see if it switches up so i go to player two click back in i can't move with this controller and then this one does move so it's working it's reading from the correct controller controller two is giving us horizontal vertical two other ones giving us horizontal vertical one all right so stop playing and let's go into the aiming part again so with the shooting or with the moving part we're just reading horizontal and vertical one and two let's just make a horizontal and vertical aim one and two so i'm going to copy my code from the well let's go set up the axes first and then we'll do the code so go back into the input manager just under project settings and input manager and then we're gonna expand out oh actually let's uh right click on horizontal duplicate it and i'm gonna name this horizontal aim one and then i need to figure out the correct axis so the axis for this if i remember right i i played with it a bit and i've lost track and i forget i think it was either like four and six or six and seven or something like that so i'm going to try axis six here for horizontal aim one and then i'm going to duplicate vertical and make a vertical aim one and i'm gonna try um like horizontal seven or something or i mean axis seven sorry so there we go aim one and drag this up and i'm gonna set the axis to again i can't remember which axis it was so i'm gonna have to figure it out actually you know what i can do to test this is just go up to a horizontal one i can change this over to um is it six axis i can do this while i'm playing even i can hit play run around and see which axis actually starts moving it when i push this controller so i've got this controller button right here oh no it's definitely not sixth try fifth okay it's not that one let's try the uh fourth nope i've totally forgotten which axis it is here eight maybe i'm on the wrong controller that would be funny right one of these axes actually controls it though i just got to remember which one i don't know if i'm going to remember it let's see see i have it saved off here somewhere let me see if i can find it maybe not i'll i'll figure it out real quick and somebody was asking about using the new input system um the only reason i'm not using is just because i'm not sure um how much it's going to change or if it's going to change like every time i jump into it it's changed in the past and then had revamps and be honest like i never know with unity systems if they're going to stay around or if they're going to end up replacing it with some other asset or something so i just use the default one when i just need simple stuff like this um normally like remembering the mapping for this isn't too bad though so i'm going to stop playing i'm just going to go back in and and fix it up so it's um let's see horizontal 1 is going to be x axis horizontal aim one i can't i gotta figure out the numbers but i'm gonna go with fifth and i'm gonna put aim yeah vertical aim one on seven and then i'm just gonna go into the script and write up the code to read those axes and see if those numbers are right or not so just go in here we'll go open up our controller aim and then here we're going to read those two axes actually i'm going to copy that out of gun or out of player copy the vertical and horizontal paste them into controller aim right here and i'm just going to name this or add the word aim here and aim here and now i'm seeing like i'm gonna actually be exposing player number here um and having to read it from player just to spin this i think i'm gonna actually cut this code take everything here and just move it into the player so cut it out go to the player and right below the movement stuff i'm just gonna put it down here i think this makes more sense and it's going to be a little bit easier so i'll make this vertical aim or horizontal aim and vertical aim like the controller aim it seemed like maybe it was going to be the right spot but i don't i don't foresee myself swapping these out often enough or quick enough or soon enough to make it really make sense so i'm going to delete this and then we'll um maybe we add it back in when we switch over to another network mode or network mode instead so that we have some separation but right now i'm not seeing it as um as a necessary thing i think it's always good to just simplify stuff as you're going along if you feel like you've over complicated something or added something you don't need just go back and delete it don't like code yourself into a corner and think that just because you've created something means you have to use it and i can't delete it so i'm going to delete that controller aim script which is going to give me like a missing script right here let's see we'll remove that and then we'll go back let's see our player should be a little bit better and simpler let's zoom out a little bit so our player now is going to read these two aims the vertical and horizontal aim and then just set our direction based on that instead of all this mouse stuff so i'll delete the mouse code and we'll figure out a new vector just by i guess creating a new direction here delete delete delete delete delete delete delete delete and uh delete that line and here let's zoom in and see what we've got so controller aim is going to shrink down to i think this so we've got the direction here we're creating it and then assigning it to be honest here i don't even know that we need any of that i think we can put horizontal aim here we can put vertical aim here and then um we can just well replace direction with transform.forward so copy this paste it right there delete that line out and now that entire script has become uh three lines of code i think that's a little bit better than a whole separate script so i'm going to delete out that extra space i might um actually i'll just refactor these into movement and aiming so let's refactor this i'll select this little chunk of code here i'm gonna hit alt enter and i'm gonna hit um aim with controller or type or i'm not sure exactly what i'm gonna name it but name it something explicit lead out the private keyword now let's make this um move with controller extract this part move with controller there we go and yeah that's it um actually uh yeah do i want to update the movement yeah it's fine so right now it's updating the it's returning back the movement to set this boolean i'm actually going to i'm going to move this into the move so i don't have a return parameter there just paste this in get the animator setting it in the movement part make this return nothing make it void it doesn't feel perfect because setting the animation is not technically part of the moving but um i don't want to have it have a return value there just yet maybe i'll cache it or something later but for now i don't need it so let's delete out that system and there we go we've got a much simpler player we move with controller then we aim with controller and we're done let's see if it actually works though saying that so ctrl shift b does a build looks like it succeeds we'll go in and we'll hit play and let's see if we can actually move around and aim or anything all right oh where's my player there he is okay i got my player okay i can kind of okay so one of these axes is right the i see the up and down axis the vertical here is right the horizontal one is wrong so i'm going to go back to my input manager and let's see where's the vertical one that i'm using that's correct vertical aim is actually six or seven let's try six here and see if that's horizontal aim nope it's not six let's try um a different one oh oh my mouse is acting up on one second open mouse okay i just smack it real quick all right let's change this to a different axis so instead of six let's try the five does that work nope okay what about uh how about y-axis is that it that wasn't the right one before or ah there we go so axis is four it's four and seven it looks like so here see it watches i push up he goes up and i go right he goes right down he goes down lefty goes left although it's not exact because notice that the direction rotation that i'm doing here is actually so if i hit left i'm actually going left um in world space and not relative to my my direction transform that's something i should probably fix we'll do that in a minute though first let's um get these axes set up and get the other player working i want to have a second player in here i've been talking so long and i haven't got a second player going driving me nuts all right so we got vertical aim two it was seven and what did i say the other axis was oh geez how did i already forget who remembers what it was was it four i'm going to play yep it was four okay we've got these two set up let's go set up the player two ones now i've got horizontal aim and vertical aim and horizontal and vertical movement i'm going to right click on the well actually let's do it on vertical we want to do it on i think i'll do it on vertical or horizontal too i'll right click on that one try to decide which one to right click on to duplicate because with this input manager you can't easily just drag and rearrange things so if i want to have them in a neat order and i generally do then i can be a little bit careful about how i create them so i'm going to go and i think there are ways to rearrange it by the way if you really care but it's a lot easier for me to just think about it for a second about where i'm going to put them so um vertical aim one vertical aim two let's add a vertical two right after here we'll say vertical aim two and this was seven and then we'll add a horizontal aim too so right click on this one horizontal aim two and this was axis four all right so now i've got axes set up for both players i closed that off i'm gonna save and i'm gonna go to file save project too because that makes it save all of my input settings my project settings and then we'll go in and enable the second player so if we click on our second player this is actually just another robot that i've dragged out here i'm gonna enable them i pulled them out in the first scene or the the first uh stream but i'm gonna actually delete them and make a new player from scratch so everybody can see that process and pick the color and then everybody can pick a color while i take a drink real quick so for the second player i'm gonna use one of these robot guys and it looks like they come in let's see a couple different colors i've already got the red guy and i'm just going to let everybody in chat say what color they want for the second one it's not the red one so if you guys want to go with the white one fine if not we'll go with any one of these other colors so just go ahead and say in chat uh which one you're going to have and i'll take a drink and then we'll build up that player set it up so that they can move around and do stuff all right just waiting for chat now see if anybody's got anything um i'm gonna take a drink thirsty and just kind of trying to catch up real quick i see a lot of blue lots of lots of blue one one for grant two for green oh now it's like a blue green war all right all right it looks like blue's got the most by by just a little bit so we'll go with the blue one first all right so to set up the blue guy we're going to need to well first make sure i got the right character here i'm going to delete all of these other prefabs except for the blue one so i'll take everything but the blue shift select them all and delete get rid of them all so i've got just this blue guy right here who just has an animator with no animation on him go over to our player actually let's rename these guys i'm going to rename this red soldier to player 1 and i'm going to put red right here in parentheses just to make it really obvious for myself that he's the red dude i'm going to move him right here and i'll rename this guy to player 2 two i'm making blue so it's really obvious to me so i don't get mixed up later and then i'm gonna set this player up so he needs an animator controller first because hit play he's not gonna animate i don't have anything on him right hit play nothing happens but we can just take the animator controller from the other player because it's the same mesh and the same model it animates exactly the same you gotta take this player animator controller and assign it so go to blue and assign the animator controller pretty simple and let's look at the animator controller real quick because it's all so simple the animator controller here let's click on play the blue player and just hit play it's actually pretty basic it has a gun play animation so by default he's just constantly shooting in this game there's never a situation where you're not shooting so that makes sense just constantly shooting in an animation and then if you're running so if we set the run parameter to true it plays the run animation that's the whole animator controller just back and forth and that's just done with a transition here that uses a condition for true on running to go into run and false on running to go out of run pretty simple and there was that one line of code in the move that actually set this to true or false based on whether or not our movement was greater than zero i think you can see that uh right here if movement dot magnitude is greater than zero it'll run otherwise this will not run all right so we got the animator on there pretty cool um let's go back to him and set up whatever else he needs he'll need a player script so we'll need to add the player script that's the one that handles the moving and now the turning it needs the direction transformer we're using that to move relative to it so that we can move along with the way our camera is without having to understand or figure out the math nice easy way to move without needing to go through that and have extra code in there that i have to go through and explain so here we can use it or we can assign it just by grabbing that direction object click on it here let's hit f over the scene view on it too or just double click on it see it one more time it's just this object it's literally just a box that's um set up and positioned so that it's facing in the direction that i want movement to be in so forward or not that forward there we go that forward right there of it the blue forward is up and then uh right is the red and so on so if i turn this you know i flip it around and controls are inverted let's turn that renderer back off all right let's go back to the player again so here we had on the player what else do we have a rigid body and a capsule collider let's add those two to it let's say rigid body and if we expand it out i don't think that we had checked anything i think i'd uncheck to use gravity because i don't remember it with following but let's double check that yeah your gravity was unchecked i think other than that it was just left on its default then we have a capsule collider so go back to the player again add a capsule collider and i'm going to hit f over the scene view to zoom in on him oh where's my player why don't i see oh i don't see the capsule it was that player i'm just blind i didn't see the capsule collider because it was clapped so expand it out and now i'll see it let's collapse everything else so you can see that the capsule collider here i just need to move it up so i'm going to drag the y up here actually just type in a one and put it at one and i'm gonna set the height to two so he's two meters tall and centered right in the middle all right so now he's got a collider i think the last thing he needs is the gun script so you can shoot expand that out it just needs a reference to a bullet prefab set that up and then i'm going to real quickly give an overview of what that gun script does uh actually let's play run around shoot and then we'll worry about the gun script later so i've got that set up let's get the bullet prefab let's see if i hit search go to assets and oh oh where'd it go oh i can only find the scene one that's not what i want i want to find the one that's actually in the project view which is in my prefab folder click on it and drag and assign i'm going to save this off i'm going to make both of these players into new prefabs because right now they're using prefabs that are referenced in the um in the art pack that i grabbed if i hit select see that it goes to my robot soldier prefabs folder i don't want that i want to make my own new prefabs off of these i've added a lot and changed them so i'm going to just drag them into the prefabs folder and make them both brand new original prefabs all right two brand new prefabs for our two players and if i hit play right now well let's see i'm not going to tell you what's going to happen i'm going to hit play and everybody can just type and chat and guess what you think is going to happen the second i try to move i want to see how many people guess it right i'm going to move and look at that so i move left and right on this guy and the blue guy is moving too i go up and down the blue guy is moving too and if i spin around they both spin around together now the reason for this well there are two reasons or one reason that they're both moving and one reason they're moving at different speeds the reason they're both moving together is they're both set on player one if we look at the player number here where's our player script player one is the number for player one two and player one is number four player one as well so i gotta change this to a two and now it would be on its own controller the other reason the reason it moved half the speed or way slower is just that the speed value here is set to five on our red player and it was set to one on our blue player i'm gonna make the blue player move a little bit slower make them move at a four maybe i'll make these like different players give one of them a special power or something the other thing that's missing is the shoot point notice the error down here i just saw it over clicking through oh i could fix that we need to assign the shoot point on the player too so i'm going to expand it out it'll expand out the hips up alt and click just expands all the way remember and then scroll down find the oh i don't have a shoot point under here let's create one let's add it if we expand out our player one see that the shoot point is actually what is a child of the right hand thumb and if we go to it we can uh well actually here's the easiest way to do it watch this i can duplicate this drag it down here and make it a child of that thumb come on right hand thumb right bam now it's a child of the thumb now the important part is by now it's way offset so if i shoot if i leave it like this it's going to be way off because this is from the blue player so the position is yeah off by like four and a half meters so really really far i need to fix the offset so just go back up here to player one i'm gonna double click on the shoot point to select it right click on the transform and hit copy component this is just going to copy the offset and since the model is exactly the same the offset is going to be exactly the same then i can double click on the character again oh that player 2 to find his shoe point i didn't actually assign it oh sorry so i've got him selected i'm going to assign the shoot point click and drag and then i'm going to go paste in the values so click on it right click and paste component values now the offset right down here at the base of the gun i'm going to rename this to shoot point um player two just so it's more obvious what it is oh whoops i actually totally renamed that shoot point for player two okay so save that off i'm gonna go back and apply these two prefabs if i don't remember if i changed them both but hit the back arrow a bunch of times and collapse these down and make sure that i have applied so i hit overrides apply all you had to add that shoot point and then we'll do the same here overrides and apply all to just update our player script oh thanks for the super chat all right so now we will clear out the error let's hit play and see if i can move two players around independently so player one moves with this one and spins with this one looks good grab the other controller here this player up spins and moves so okay oh wait almost move so it spins moves yeah so it's looking good um there are a couple of really obvious issues though the fact that the bullets aren't shooting and every time i let go it just kind of like resets and they they seem to just snap back to that default zero position or that default orientation so let's adjust it real quick let's make it first so that they don't snap back to that orientation and let's figure out why the bullets are not going in the direction that they're supposed to go they're just sitting still my guess is that they're not getting a proper direction and that they're moving at some speed of times zero zero zero on the vector all right so let's see for our let's see for our aiming if we look at our aim with controller part here we set our transform forward to whatever vector we create using our horizontal and vertical so that's just using these axes if we're not pushing anything though the magnitude of that or the value of both of those should be zero and i think if it's zero then we should just um not turn them so like if they're not pushing left right up or down then we should probably not do any adjustment of the direction i'm going to say if horizontal aim is not equal to zero and vertical aim is not equal to zero then we could do the transform for let's try that out now this might have issues with our controller if our controller sensitivity is off and we're getting numbers that are not exactly zero so let's try it see we click and we aim and you can see it's still that's a okay our rotation is i see what's happening so it is working but our characters kind of spinning around the reason he's spinning around if i look at our rigid body is that we're not actually freezing or locking the rotations he's just kind of rolling on his own um and before he wasn't doing that because we were setting the rotation every frame so if i hit freeze rotation here just lock his rotation down then click over here again i should see that he snaps and he just stops acting weird so now he looks in the direction that i push and he doesn't do that weird rolling so let's stop playing go check freeze on both of those players so pull out or expand them select them both expand out the rigid bodies and hit the freeze box on all of them thanks again for all the super chats there was awesome so these streams are a lot of fun amazed that so many people like to follow along and join and have some cool input too all right so let's see we've got our players set up they should spin let's try it and make sure that i can actually spin in the right directions real quick so i can spin i release and it doesn't keep spinning and same with this character spin release and it doesn't seem to keep spinning looks good and i can still move around right yep so i can now i can move and aim and shoot but i need to fix these bullets because they're acting stupid and they're just sitting still let's go select player one the red one okay right now i've got my two guns here just looking at these gun scripts i got a gun with a delay of 0.1 and a bullet speed of 13 and then this guy's got a 0.2 and a bullet speed of five but neither one of them's moving at all so let's open up the not that not the bullet pretty fab i double clicked on it let's open up the gun script and take a look at how it works and uh why it's broken so for anybody who didn't see the previous stream you get a real real quick intro to a pooling system a super fast pulling system to handle a single solution um our single problem here and a real quick overview of how this thing works so the gun setup right now just spawns bullets using a bullet prefab the bullet if i go to it you see it just deals with collisions if we hit something we uh take some damage and we also add ourselves back into the guns pool with this add to pool so all this bullet does is keep a reference to a gun and then when it hits something goes back into a pool if it happened to hit an enemy it also hurts the enemy if it hits a wall or something that goes back to the pool um it does also however fly off forever and never get re-added to the pool so that's an addition or a fix that we could probably make later but let's go back to the gun so it has this bullet prefab it's also got a delay variable for how fast it shoots point two is five bullets a second and then how fast the bullets go right now it's set to five so that's five meters a second is the velocity that we're using we got a next shoot time a direction that i believe is unused and that's probably the reason we have a queue of pools and a queue is essentially a collection like a first in first out collection where you put things in and then you can see if there's anything in it and then take something out of it if there is something and you can just ask it and it'll give you the the oldest thing that went into it is the first thing you'll get back out every time you request the next thing from it that's essentially like a collection or a list of bullets that we're saving up or reusing and we have a reference to our player in a wake up i think we actually saw when we did that so an update we checked to see if we can shoot and we do shoot can't shoot just checks to see our if our time is met and then our shoot method checks to see well first it resets our shoot time so that we can't shoot again so we use that we use our current time plus our delay to be our next shoot time so if we're like 10 seconds into the game we'll our next shoot time will be at 10 seconds or 10.2 seconds into the game so we won't be able to shoot until we get to that time uh then we get a bullet from our pool or spawn a new one here it just checks the if there's something in the pool grab it otherwise instantiate the thing set its gun to this so that it knows how to get back into the pool and then return it and then eventually it goes back into the pool with that uh re-add tip had to pull just puts it in the bowl very simple very very small pooling system that'll just handle this one little scenario we have so then what else do we get the bullet we set the position we set the rotation and then we set the velocity using this direction and that's the problem the direction is never being set because we were using the mouse position to get that before we're not anymore so we can just replace this with transform.forward that's going to be the direction that our character is facing towards seems good enough to me if we go back into unity and see if it works our bullets i expect are going to start flying forward here we go bullets are flying out i can move and aim bullets are flying out of the blue dude and i can move a name he just kind of sucks because he shoots way way way slower let's uh speed up his bullet a little bit let's change these to be like uh maybe he'll shoot i don't know i'll change it i'll just make him like 15. i'll make him faster he's bullets to shoot fast and uh less frequent i don't know why before player two gets nerfed right all right so we've got uh two players let's go turn on some spawners real quick get these guys spawning and then see what the next step is so play get in here and i don't know how i'm going to kill lots of bad guys with uh just i don't move and i just try to use the thumb sticks ah this might work might have to get another player in here eventually but you can see i i can actually kill things and get points but i think the next thing i want to do well there are two things i want to fix the pooling issue where the bullets keep spawning and they just fly off forever let me show you what that looks like the other thing that i want to do though is separate out the scores because right now our score system only deals with one player so i'm gonna turn off um the spawners just show you the bullet thing real quick take a drink and then see you guys want to see the fix for the pooling real quick so that the bullets actually go away and don't live forever or should we go into um separating out the scores so that each player gets their own score we'll do both of them but which one you guys want to do first i'm just gonna watch chat while i take drinks and see what the answer is the pooling was the first answer cool okay it looks like there's something and some requests for the pulling and it's actually really simple you saw all those bullets that were just spamming out and never going away because they don't hit anything actually here let me um let me show it one more time like up in detail while i'm not taking a drink and actually like actively showing it so i hit play here and if i aim up at a wall here you see that like the number of bullets spawning here doesn't really go up you can just look down here in the list and i'm oh oops now i started shooting out to the side and bullets started going up but if i shoot here they're all hitting something and getting reset but if i shoot down this direction that way i got to go a little bit further where they just can keep going on and on forever if i zoom out see these bullets ah they're not they're not actually getting on forever hold on gotta get them if i get them aimed the right way are they gonna make it oh so close i promise i will get these bullets flying off the screen forever there we go so if i get them flying that way you see they'll just keep going on forever and ever and ever because they never actually hit um hit a hit anything so there's nothing to reset them or knock them back into the pool the solution forward is actually really really simple we just go into our bullet and just when we enable our bullet we can just set a timer to re-add ourselves to the pool so we can just set a maximum lifetime or something to that just go up here add a serialized field make it like a uh float make it max lifetime i'll give it a value of like 10 maybe it go on for 10 seconds that seems like a long lifetime but it's fine it's not going to be i'm not going to end up with too many bullets i don't think now go down here and we'll just add in and on enable so right below right below my on collision enter i'll say on enable and i'll get rid of that private keyword and i'll paste in my mac oh wait what i want to do here let me think i'm gonna start a co routine oh wait no hold on i'm thinking for a moment am i doing anything update no i'm not i'll start a co-routine no i won't start a code routine i don't want to disable this i don't want to kick off a co routine for every bullet so instead i will say that um enable time equals time.time i'll add a field for it and i'll turn it into an expression body method so when it gets enabled i'll set the time that it got enabled then i'll just add an update and i'll say if um time.time is greater than oh actually let's call it disable time i'll rename enable time to disable time and then i'll make it equal to time that time plus the uh max lifetime that way it will disable at that time and i don't have to do the calculation every frame so if time.time is greater than or equal to disable time game object.setactive there we go and delete out the private keyword that should fix it i don't think i need anything else i'm going to get rid of that private keyword there save it off go back into unity hit play and i expect that my bullets should now both no longer live on for infinity into yeah let's see so i keep shooting let it go out and let's watch the bullets um just go find a bullet if we watch them they should start to disable wherever that 10 second mark is yeah i guess it's right about here that's how long they live for 10 seconds then they go back into the pool oh thanks again for the super chat all right um let's stop playing now that we've got the pooling fixed up let me think could add in um i want to add in some super weapons um i want to set up the high scores for the scores so that they work with multiple players um i think i want to get in real quick a couple other simple features that i want to get going so let's see let me think um what am i going to do give it just a second try to decide so let's see a new super weapon could be cool to like let's make scores first so that i can give the players power-ups and they could like pick up a weapon and do something cool and then you actually see like there'd be a reason to be the one that want to get the power up i think having the scores there is gonna is gonna be the more exciting part for me i don't know maybe i'm weird all right let's go try it out let's go expand out the canvas where we have our high score system set up and take a look at it so our high score system right now is actually set up on the campus or our entire score system it's just a single script on the canvas because score system's not very complicated we're not doing much with it it doesn't really need to be anymore if we were doing multiple levels i mentioned before i'd probably do something slightly more advanced but i got a single level and the score system kind of handles everything so right now the score system keeps track of a number of points we can have a single score system and uh it's really just a highest we will have a high score and then a number of points total like we don't have a a score system per player so we need to decide um how to do this it can either add in a score system that keeps track of the score for multiple players can add in a score component on a player that like keeps track of that player's score um or i don't know i could just make this score system yeah handle them both um let me think but what i want to do here first i want to get rid of this private keyword because it doesn't take any any thinking and i can just click keys a couple times without without trying to figure out what i want to do and then we'll go through and um actually do the score system i know i'm going to need another text object i think i'm only ever going to two players right now so i don't think i'm gonna over complicate it and make it at a player level i'll probably just expand this to go to two players i think if i was gonna go to like four players or six or something else make it more advanced i would probably split it out a little more but i'm thinking that i just want to handle um the score for two players so i might make this um an int array or i can make it like 31 points but i'm going to make an inter array so it's going to be an array of integers of points and i'll set it to equal to a new interarray of two i get two integers four player one points player two points and then here i'll pass in instead when we do add points i'll say points and do a print player number and then we can just add in for the player number so oops that out and paste so what we're doing here is turning the player or the points from a single integer into an array of integers and then accessing the one for the player number to increment so we'll have a points zero which would be like the first player and it points one which would be the second oh i don't really like i'm gonna change this instead of it being a man i'm gonna make it two inch as much as i don't like it um i don't like having an offset integer either so i'm gonna make it points um let's call it player one point actually i'm just called player one hit player one and hint player two and i'll just i'll just use those for now i think i think that that's gonna be it's not perfect um but only because i only have two i'm thinking let's change it we are going to and it's tough i i think i want to do a dictionary keyed by no i'm going to keep it simple as much as i'm fighting myself to do it so on enable we'll set the i'm just going to make a player one text in a player i'm not going to over complicate this player 2 text and a player one it's so hard to resist the urge to make it more extensible but i think it's a good habit to show because if i if i go in and over build this i could spend like the next 40 minutes building out a score system that does exactly the same thing a slightly less performant and a little bit harder to understand i don't think i need to do that so i'm just going to make player one and player one and i'll copy that and paste it so we'll just set player one text to player ones points then player two text to player twos points in on enable and then we'll do it when we do our add points i'll just look at what this player number is if it's one we'll do one different two we'll do two and call it simple i i don't again if we're doing more players it would make sense to extend it out but really like it would just be an it'd be an over engineered waste of time um just to show that i know how to use a dictionary i'm gonna not do it all right so add points so if player number is equal to one then we'll say point or player one plus equals points and then we'll say else player two plus equals points i i didn't put two there but the idea that should be a two um and then i'm going to take this part right here that says updates that updates this text i'm going to take all of this code hit alt enter extract it and say update i'm just going to make single method that updates the text i don't have so much code in here take that call to update text and i'm just going to replace all of this right there and then we'll say hey if oh wait but i need to figure out what the total points is so here i'll say if player 1 is greater than high score then uh high scores player one and then we'll just do the same i really don't like having to do there twice let's i'm not setting the textbook i think it's true okay i'm going to take this bit of the text i don't set it twice i'm going to cut it out of here and paste it here so it will only update i'm going to update both of this i'm not going to i'm going to if i'm going to be lazy i'm going to be all the way lazy so i'm just going to call update text every time we change anything here so we'll do update text we don't need to do the set text here and um we do need to do the high score part so we'll say if it's that i'm going to write out the code and then i'll talk it through so if player 1's score gets greater than the high score and we'll do that i'm going to move it i'm going to move it and zoom it okay so we'll add points we'll add in a summary number of points for our player number if the number is one we'll add it to player number one and if he's higher than the high score we'll set that to the highest score and i'm just gonna literally i'm gonna copy this and paste it for player two and then we're gonna delete out all the rest i would replace that with a two and a two and a two and i really hate having two variables with player numbers but i honestly feel like i'm i'd be over complicating it if i uh if i optimize this anymore right now all right and then we'll just set the high score to whatever our high score is every time oh every time we add points this is such a struggle like i feel like i'm writing a bunch of code that i just want to uh i struggle to not delete but it's okay as long as it works and it's readable and understandable i think that's the most important part all right let's fix up our formatting real quick here i think i got an extra brace here and then we'll zoom out and take a real a real look at it and explain it again one last time so we'll add points if it's player one we use player one's value and set the high score updated if the if the player one's new scores higher than the high score otherwise we'll do it for player two and no matter what we'll update the text for everything just being lazy on it and doing wide updates for everything but right now add points has an issue because if i look at ad points the call to it right here is right here and we don't have a player number so i need to fix this call to it and then i'm going to need to fix this call and actually say which player number should be getting the points when we call add points right now our system should be able to handle it we should be able to set up points for a player one and a player two and if i was going to three i would totally change this but with two we have enough that it'll work we just need to actually make the add points work so copy out this parameter i'm going to paste it right here into the public static one you'll see why this is public static in just a second and then we'll paste in the player number here in our public static version of add notice this one's not public and static because the way that we're wrapping up the singleton instance of our score system but in this one now we're adding the player number if i hit ctrl shift v i expect build error there we go and double click on it it's in the enemy script right here on line 40 and it's our score system dot add call to point value so when we take damage from something we need to know what player is dealing the damage to us right now we don't have any way to tell we need to be able to pass that player into the score system so we're going to have to pass in a player number here but we don't have a player number so we're gonna need to figure out how to get a player number into take damage let's look at where take damage is called from if i hit shift f12 i can find references ah that didn't work that's right i can click on this button too and just find them here you can see an enemy take damage on the bullet we call well we pass in the point that we hit so we could play a particle effect there but we also need to give it our player number we still don't have our player number so let's give it our player number here we'll pass it in on take damage let's go take the image and make it a parameter first i'll copy player number we'll make it the second parameter and player number and this only has one reference so i only need to fix the one spot that's calling it go to that spot and we'll pass in our player number here oh but look we also don't have our player number here so we need to get it from something else so where could we get it from our gun i guess technically has our player number right our gun is on the same object as our player so we could probably just get it from our gun um yeah we could just get it from our gun right when when we shoot it off we can get it and re-grab it so let's assign it uh well actually hold on let's take a look at this real quick let's go look at how we set our again so when do we set the gun that gun happens whenever we get a bullet and we instantiate it the first time this is going to be an issue let's take a look at why it's going to be an issue but let's set it up first and then see the issue make it happen and then fix it all right so here we set our gun and let's say that we wanted to um just get the player number on collision enter that's what i'm gonna do i'm gonna not cache it right now or just get it on collision integer so we'll add in some braces here i'm gonna say hint player number equals gun dot get component player top player oh i don't have player number exposed player number so let's go expose player number on there and to do that i can just go i just hit f12 i hit alt enter to generate the property and hit f12 to go to it then i'm going to go just delete this chunk code make an expression body property and make it return back player number i'm just exposing it so i can read it from that script let's see if that fixes the problem now i should be able to get the player number and make the thing take damage i think this is going to work but there's definitely going to be a bug and i think it's a bug that's worth showing this kind of thing that catch people off guard all right so oh i'm going to enable a spawner and i'm going to actually go set up the canvas now so that we can see our text objects so let's go to 2d mode and in the scene view i'm going to go to the score and hit f there we go and now we can see this is the score object right here or the the one in the middle is the score and the one on the top right is the high score i'm gonna change this up i'm gonna make the score be on the left for player one and the right for player two then i'll just put the high score like up in the middle somewhere small so i'm gonna name this uh score one and then we'll align it to the left so expand out the text mesh pro field and hit the left alignment and duplicate it and make a score 2 control d or command d to duplicate it by the way and then align that to the right now i've got two score objects i'm going to shrink the font size so select them both turn this down to like a i'll go like a 100 something that's a little bit more reasonable i'll take the highest score and i'm going to move that to the center and i'm going to shrink this down even more to like a 60. something that's a little bit smaller so i got score one and two go to the canvas and we'll assign player one text to score one and player two's text to score two save and hit play let's see so now i've got two score objects i've got one player let's see if he kills something if he gets points so he gets points he gets points he gets points he gets points looking good so far um i'm gonna kill these guys let's i'm gonna pause it enable player two unpause it and let's see if i can uh keep killing these guys and uh what i want to do is get player two shooting at them and not player one so player two oh here actually i'm going to crank up player two's uh fire rate a lot player two is gonna shoot super fast point zero five that's wrong bam so he's got a nice strong spray and then player one will go this way now watch player one's score oh actually you might not see it now cause it ah okay i messed it up let's try this again i'm gonna stop playing i'm gonna re redo it and show you the the actual problem i've got player one here i'm gonna let him come in i'm gonna let him shoot a bunch of bullets real quick bam bam bam bam bam he shoots pause and then i'm gonna go enable player two and disable player one oh actually you know what my bullet didn't pull hold on i keep doing this wrong what i need to do is get my bullets to go back into the pool i need to stop the uh spawner i think it's causing me stress of these mods these robots trying to kill me overwhelming me all right so let's see so i shoot and bam bam bam all the bullets are going in and they're getting pulled right now we should see bullets getting pulled and i'm gonna pause go enable player two and disable player one now i play and i got this other player here but look at the uh the bullets i should see the same bullets getting used here we go look through them are they oh they're not getting reused oh i was wrong i was thinking that they were going to get re-added to my gun but it actually makes sense they're actually getting assigned by the player i was totally wrong and i thought i had an issue that i don't have so this actually is going to work just fine isn't it let's save let's go i'm just going to go blow up a bunch of guys and see if it uh if it works or not hold on a second all right sorry just had to clean that up real quick all right now let's um let's go actually test out the score all that nonsense was uh me thinking uh me thinking that my thing wasn't working and it actually is so now if i hit play get both of my guys in here i'm gonna aim them around i'm gonna get them kind of lined up the right way i'm gonna turn that spawner on again and see if i actually start getting uh getting bad guys and getting points for both both my characters i expect that player one and player two should be both be able to get points now let's see player two getting points yep player one gets points and player two gets points the scores are independent all right let's see ah okay i want to uh make it so i can reset my high score though real quick so that i can actually do a little bit of competition here and have a new high score where i don't have to go so freaking high so i'm going to add in a button actually let's make our uh let's make the high score object here into a button real quick so i can just click on it to do that i'm going to take the left score i'm going to shrink it down so it doesn't go all the way across the screen and actually let's just anchor it to top left here like that take the right one and i'm gonna anchor it to the top right here and shrink it down too so it doesn't take up the whole screen then i'll select this one right here let's just add like a a button to it i'm gonna center it here in the top in the middle and yes right now every gun has its own pool so somebody's asking in chat the reason that every gun has its own pool it's not really intentional it's just kind of like a side effect of the way that it was coded initially for one thing when we start up a bullet we assign it to a gun and then when a gun looks for an object it only looks for objects that are assigned to it i was thinking that we were having a reusable pool where i was going to need to reset that player number i really don't so um we're just reusing them for the bullet and it's probably fine for that case to be honest because it's always gonna fill up to the maximum size that two players could shoot out so it won't be a big deal i think that that'll actually work now i want to set this up to be a button though this high score object or make it so that we can just um click on it so i don't should make it a button or just make it a click thing i think kind of up in the air i think i'm just going to make a little button i was thinking about just making it clickable but i think i'll just make a little button so i'll go right click make a button a ui text mesh pro button i'm going to move it i'm going to move it right up here make it really really tiny and then remove the text or let's just replace the text so i'll replace the text with a zero this is going to be my zero out button this is going to reset the high score so i'm getting this reset i score the reset high score button and then i just need to assign it or a an on click reference to actually do the resetting so i'll hit the plus on on click assign my canvas and then if i click here i should see my score system but there's no real reset method so let's go to the score system and add one real quick so go to our oh let's just go into visual studio go to the score system let's hit a or make a reset high score so i'm going to go right at the top say public void reset high score and then here we just need to set our score high score to zero and then uh set the player prep for it so copy this line right here where we actually set our high score paste it right up here we'll set it to zero and save that should be enough now i need to go back into unity and actually hook up that button for the the method to the button so we've got the canvas here if i go back score system again i should see a reset high score there it is and i save my scene hit play oh you know what i want to actually make it update the ui element too over here let's hit play oh yeah listen hit play you'll see that it doesn't actually update the ui element when i kill him if i stop playing and play again it's going to reset it or no one when i hit the button but if i just go out here let's get up get a new high score again real quick and then i'll make it so that it resets when we actually hit hit the button just blow it up bam it blew up okay so now i should have a new high score of 700 play let's see it again pick out a high score let's go reset reset it in the uh or reset the text real quick go to score system when we reset the high score go bam update save it off go back into unity again hit play now i should be able to just reset that high score on demand play and clear it out bam now it clears that so somebody's asking about a text mesh pro oh about whether or not they'll make the normal text i was always wondering if they were going to make um text mesh pro the default or something but i don't know what's going on hopefully it uh it happens but there may be some technical reasons that it hasn't happened yet for anybody who's not familiar with it though it's an asset pack for unity um it used to be an asset pack now it's a give me a package in the package manager it allows you to just do prettier text so you can do nicer looking text i think it generally is more performant but and it runs better on things on a bunch of devices but it also lets you do a lot of other things that the default text won't do um by default it comes with a lot of cool fonts and a lot of different um options here so you can set up this glow or these i don't know what the logo ones for outlines there's a bunch of different options here for adjusting it and right now i'm on the mobile version of it if you change it off of that from text mesh pro mobile to text mesh pro distance field i see that you start to get other options too there's underlay options lighting options you can animate it make it bend and curve and do all kinds of stuff in fact i think if i just select this and hit type the where is it where's the high score text there's curved oh maybe i don't have it in here yet so if you look at the text mesh pro okay it's not in here there's a package that comes with it though when you import it there's an extras and there's like a curve effect and a whole bunch of other really cool effects you can just drop in there and they just kind of work and and it looks nice makes it makes your stuff look nicer and and it's easy all right so let's see we've got multiple score systems set up um got multiple players set up and moving around i do want to get them onto the arcade cabinet soon but i'll probably have to go offline to do that because i got a cameras and stuff um it doesn't really aim over there or anything and you wouldn't be able to hear me i'd be over there and nobody would hear a word i see i got this uh mic set up now to kind of see it hanging here but it's not actually hooked up or plugged in yet so i'll get that set up sometime and be able to go onto the cabinet um but for now let's see what else i feel like i need to add in um i want to add in some new feature something else in here to do something maybe like a special attack or like a bomb or something yeah i want to do that like uh let me come up with two different ideas and think of like maybe a bomb that we can shoot out like the the players could pick up like a special thing that they they get and maybe they just made it like special attack you could use every now and then hit a button and it shoots out a bomb or we could do a power up that speeds up the um the attack speed so i'll go with one of those to either a power up that you pick up that speeds up your attack speed um or a special attack that you can just hit a button and it shoots out a uh a bomb and maybe hit it again and it explodes so which one do you guys want to see like a any a bomb type thing or a power up where you get something better go ahead and just type in chat let me know what you guys prefer and then i'll go from there take another drink and think about it for a second to figure out exactly how i'm going to code up um the system once there's a vote oh a time bomb that could be interesting to like when you just drop and then it blows up after a couple seconds um and then damages everybody around that could be really cool that'd actually be a fun one i'll do that let's try the um let's try the bomb one first i'll make it so um i don't know i guess you know what i'll do i'll make it so that you can just drop it and then it'll blow up but if you want it to fly forward you'll just add the code to set the velocity on the rigid body so it won't be any different right all right so let's do that we want to make a bomb i need something to blow up so that means i'm well you know i'm not going to make i'm not going to get an asset for it first i'll just use a uh a red sphere or something that'll be my bomb it'll be like my my little kaboom all right we're going to 3d mode go to our bullet here and i'm going to create a new object so go game object 3d object and we'll make a spear i'll hit ctrl shift f to move it to me and i'm going to make this thing oh actually it's it's already relatively big so i'll just leave it full size right now go into our art folder do i have an art folder let me see i do not have an art folder so i'm going to make an art folder so i can make a material my beautiful material skills i'll say art go in there i'll hit enter and right click create and we'll make a material where's material this list is so huge well there's a lot of stuff i guess i'll call it red actually i'm going to call it bom maybe maybe i'll actually make a bomb material later also if somebody has a cool bomb that they think i should use that um there's an fbx i can just grab or download or something off the asset store um feel free to post it in chat or something may just switch to it after or as we go along so i got the material here set it to red and i'll assign it all right so let's um let's go to the inspector for our bomb again i've got the material selected so select the sphere right now name it to bomb and then let's see what do i need to add to it i want a i want a trigger do i want a collider what do i want i think i want to collide i actually i have a glider i'm going to add a rigid body too i kind of feel like it should just maybe go rolling out like just kind of roll it forward all right so we'll say that and i don't have an art folder by the way because i just imported an asset pack for this one so i didn't actually drag them into an art folder like i probably should have all right so i've got a ball here that's ready to roll if i hit play it should just kind of drop down and i think i i probably could feel like knocking around right let's see bam yep i can walk over it kind of push it um oh i can i can't really push it but i could walk over it it fell into the hole there um i've got my bomb here and now i want to make it blow up so let's add in a script to make it actually do a countdown do some timer maybe do a little bit of flashing and then blow up so we'll go into scripts right click create a new one new c sharp script and call it bom and then let's see so for a bomb i want a couple things one a radius for how wide out it should blow things up um a time for how long it should go for and maybe anything else like i guess like a damaged amount right i think the first thing is the amount of time so i'm going to do this i think in the start we'll just kick off a co routine and wait and see so let's add a serialized field for the um explosion time or let's call it countdown time and i'll default it to five seconds i'm going to change start to be an ie oh i need to make this a float i'm going to give it a type there so it changes this to ienumerator so that i can actually yield return in my start method if you haven't done that before it's a way to um avoid having to create a co-routine and still do co-routinely like things and start your start method will essentially run like a co routine if you make it return i enumerator instead of void so i say yield return new wait four seconds countdown time and then let's say game object dot set active to false that's essentially what it's going to do right it's going to do a countdown it's going to do some damage here so maybe right here i'll do damage and then it's going to set itself to inactive or even just destroy itself in fact i just say destroy game object i might not need to pull these if i'm not going to bomb do a whole bunch of bombs or anything or maybe i could add them to a pool later but for now let's just make this thing a bomb that explodes so this will make it wait for some countdown time but i said i kind of want it to flash and like give a countdown timer so i think what i want to do is add a a text object up above it so maybe there's like some little text floating above it or something um or maybe just tint the color maybe you know let's start by just flashing the color real quick so we'll go back into the bomb and instead of waiting here actually let's let's hit play and make sure that it works right added code it's always good to make sure that our code actually does what we're saying it does so go in here add in my bombscript hit play i expect the bomb to just disappear in five seconds one two three four five bam there we go it's gone all right so that is working now i'm going to make it do like a countdown though so that it doesn't just disappear instantly so that it disappears and like flashes or something so we'll say instead of waiting until the countdown time is done i say that uh well let's make it disable time or destroy time or explode time explode time equals time dot time plus countdown time and this might look a little bit familiar right so generate a field for it and we'll delete the private keyword by hitting enter we got an explode time that would be the time that we want to blow up at and it will say wow time.time is less than the explode time we'll do some loop and then in the loop well we won't wait for the entire countdown time we'll just wait for a frame so do yield return null and then maybe do like some sort of a flash right on our um on our materials so say like uh get component renderer dot material dot color equals um new color whatever that new color is gonna be for the frame so the new color could be i'm going to make that lower case i'll make a color new color equals new color and here we'll just give it like red but with some random red value here i'm just going to make it randomly flash it's not gonna look beautiful or anything don't get excited thinking it's gonna look great uh somebody's asking why i remove the private keyword just because it's redundant and i don't need it i used to leave it there all the time so things would line up and i realized that it just made it so there was more words to read and getting rid of it helped so let's make the color the r part of it the red be the random number so say random red and then zero for the green and zero for the blue now i'll make a random red float by saying float random red equals random.range and we'll go from zero to i think that color uses zero to one or zero to 255. oh yeah zero to one i get them mixed up sometimes so you look if you put the mouse over it you see that it says it constructs a new color hopefully you can see that let me scroll down with uh rgb components and sets a two one one just tells me oh yeah these are zero to one i always get mixed up there so if you're thinking zero to two fifty five that's that's that's not it alright so that should give me a random color it's obviously it's going to get the renderer every frame probably a bad idea but whatever i'm not worried about it it's a single bomb and it doesn't matter at all let's hit play i got a bomb there and it set itself to solid black okay so maybe i was wrong there maybe the um the value wasn't wasn't one it was 255. let's try that again let's see rgb like i said i get them mixed up all the time and then sometimes i look at the tooltip and get myself mixed up there we go that's better now it's setting to random redness values you can hardly tell though i think i think it looks really ugly in fact you know what forget about the random redness let's do an animation on it let's create an animation for how it's going to look yeah i think that's better i'm going to go in here go to animation folder we'll go to the animation window window and animation i'm terrible at making things look pretty but that was too ugly for me all right then we'll hit create and make an animation for our bomb save off in the animation folder i'm going to call it bom blink and then we'll start recording so hit the record button here and what i can do is just adjust the colors of the material right here so i can start it off so that maybe the bomb starts off kind of like uh maybe i'll even start it off like black right like start off like black with like tiny tiny tint of red and then we'll go over to like um the one second mark and i'll leave it black so i'll go like just a tiny little bit lighter here tiny little bit less right so it's going to slightly get a little red then i'm going to zoom out here so there's this mouse wheel to zoom out and then i'll go over to like the two second mark and let's make this um actually no let's go to like the one point really close time thanks for support by the way oh looks like somebody's got uh miranda found a a cool bomb model too may i check that out after this let's get this set up um so i'm going to change this to like a bright red here so here let me drag through so you see it's like dark and then goes to oh that's a bright white that's not a red let's change that to a bright red so click on the keyframe here click here and change this to red i'm gonna go over to here and maybe go like back to a black so i can just copy this color here copy and paste and then copy and paste again now if i hit play or stop recording hit play i should see it go like a black and then it does a little flash i think that that flash is probably too fast i'm gonna stop playing and i'm gonna go clean up these keyframes again so let's see i go here i'm oh that's a bright white that's that's why i messed up that keyframe i added in a another one instead of modifying it all right so there we go red black and then this should go back to red on this keyframe and then back to black so what i'm going to do now i've got this little repeating pattern here of this red black is it even repeating is it oh i'm not recording ah sorry so if you watch that and you're like hey jason hit the record button sorry i didn't hit it there it's this button right here the reason it wasn't changing is i'm not changing the recording here i'm changing the actual button the model or the material on the placed one i need to hit record go into record mode then click on the keyframes that i want to change there we go and then change them so here we go i'm in record mode change that keyframe to red that looks better now i got a black one a red one a black one and then we'll click on this one again and make it red and then what i can do is just copy and paste these and drag them and kind of expand maps i've got these keyframes here copy them and then i'll click over here and paste click again paste and let's just hit play and see what they look like real quick and see if i want to slow it down a little okay that looks pretty good i think um i might actually let's uh copy these a little bit more i'm going to copy them so that it goes all the way out to like this uh five second mark right so paste it paste it and then i'm going to select them all and what i can do is just expand this out just by clicking and dragging right there and then i think i'll probably just delete out a couple of the keyframes in here a couple of the beginning ones so it doesn't start as fast and then it slowly kind of picks up all right hit play again there we go now it's an animation that at least kind of looks a little bit better let me get rid of a couple more key frames in here so stop playing hit record again go back in and just grab a couple more of these out of here a couple more of these pairs but it feels like it's slowing down a little bit okay i think that's probably good i'm going to save that off and then let's make the animation actually play so i had to uncheck record and then we'll go into the animator section and we've got this bomb controller that was automatically added when we added an animation it added an animator and it added a controller if i double click on it you see that it's actually got the uh bomb black bomb blink already playing automatically that's the default animation here so whenever this thing spawns it's going to auto play that animation to be honest it's actually totally fine and i don't need to add any extra code right i just need to make sure that my timing here now matches with my animation this is one downside to putting it into the animation if i want to make it scalable and adjustable i'm going to do something with that animation probably but for now i think i'm just going to leave it around five and call it good um somebody's asking about doing some tweens or something else for it too you could definitely do that for the flashing again i'm just terrible at making like really pretty things especially doing them from code so if you're showing an animation showing how to do an animation let people who are not able to do it in code be able to kind of go through and figure out a way to make it look nice and and maybe set up a bomb that does kicking or spinning or other cool stuff you can even animate some text or other things that you want to do there alright so i got the bomb it should blink now i'm going to set it up so that i can drop the bomb right now we don't have any type of a fire button or any way to like shoot something what i want to do is make it so the player can just drop a bomb and you know if i think i'm just going to make it roll forward so i actually like use physics that'll roll forward and then after the time when it finishes it'll blow up and kill everybody so let's make the player be able to drop them before they would worry about them blowing things up so i'm going to go into here let's see enable the animator because i don't know why that was turned off i'll save my scene let's go to the project view let's go actually let's go turn our bomb into a prefab real quick to take the bomb drop it into the prefabs folder and then let's go make our player able to shoot a bomb so i'm going to go into the do i want to do this as a new script or do i want to do it in the player i am going to need the player number to read a button outside of that i don't know if i'm going to need anything else i feel like i'm going to make it a bomb dropper script so that way i could uh adjust it that way i can make it somewhat separate and not have it be directly tied to the player vary it a little bit maybe it could turn into a power up or something else so let's say um we'll create a new script and call just call it bomb dropper create c-sharp script bomb dropper and then we'll add it to both the players so i'm just going to select them both before i forget add it to both of them and then double click on it to open up the script the bomb dropper script is going to need a reference to the bomb that it spawns so i'll add a serialized field of type bom and give it the bomb prefab name and then we need to i guess just check in our update if we've pressed the bomb drop button for that player and if we should drop a bomb so we'll go in here and we'll say let's give her to start get rid of this comment on the update say if should drop bomb then drop bomb pretty simple we'll generate the methods for it generate should drop bomb and drop bomb should drop bombs just return back i guess whether or not um for now we'll just use a timer just like we do with the gun so we'll return back whether or not the current time is greater than our next uh drop time so say return time dot time greater than or equal to next drop time generate a field for our next drop time hit f12 and go to it and i'm going to delete out that private keyword real quick and then we'll um well set up our drop bomb so dropping the bomb we need to do two things first we need to set our drop time to our or our next drop time to whenever we want to fire again so that way if we have a problem with our bomb dropping we try to drop a bomb out there and there's an error or something the number gets reset and we don't keep calling it every time or the the next time gets reset we'll say next drop time equals time dot time plus our delay so let's say underscore delay and then we'll generate a field for delay and hit f12 and go to it replace the private with serialized field so we can modify it in the inspector and move it up here i'm gonna give it a default value of like five i don't think that we should be dropping bombs often five is probably way too fast but to start off with our testing i think it seems like a decent number all right next when we drop a bomb we want to spawn the prefab at our position and then i guess just roll it in our forward position so i'll say instantiate our bomb prefab at our transform.position and our transform dot rotation and then we'll get the rigid body component of that thing and just kind of push it forward in fact let's make the bomb the bomb is already using a type of bomb so say bomb bomb equals that and then we'll say var rigid body equals bomb.getcomponent rigidbody and then if the rigidbody is not null so if we didn't forget to add it is not equal to null then we'll say rigidbody.velocity equals and i'm going to use our forward vector and then um just like some launch force so i'll say transform.forward times um release speed or release velocity and hit alt enter and generate a field port f12 to go to it replace the private with serialized field and make the vector 3a float give it a default value of i'm going to go like three three meters a second seems fast enough and i'll move it up there to the top delete out these using statements and this extra space get rid of the drop bomb keyword or the private keyword on dropbomb and i think that's good so this should allow me to drop a bomb out um every five seconds and push it forward if it has a rigid body let's go try it out so go and do oh wait i lied because right now it's just gonna con oh i didn't light it's gonna constantly drop out bombs it's not reading input let's try it out though see if my guy can just drop out bombs non-stop so he's got a bomb dropper here i've got it on both of them let's go to the prefabs folder i actually have both players selected and i'm just going to take the bomb and assign it as the bomb prefab save hit play and let's watch as player 1 just starts dropping out bombs is he is he dropping up bombs oh wait oh there's an error what's the oh there you go got a bomb there it drops out and starts flashing and a bomb there drops out starts flashing and so so the bombs are dropping out and they're working now one thing i want to do is i'm going to spawn it maybe like a little bit ahead oh it looks like a spell release wrong i need i think i want to spawn it just a little bit in front of me and make the release speed much faster let's make it like a 10 on the release velocity let's see so i move around and there we go the bomb just kind of goes flying out that looks a little bit better but i want to um again fix that position and i also want to make it so that it only fires when i hit a butt let's go check that out we'll go back to our bomb dropper let's make it so it only fires or only drops a bomb when we press the bomb drop button so the first thing we want to do is we'll check in our should drop bomb that our time is valid because if it's not time to shoot we don't care about the input so we'll say if our time is greater than that greater than our next drop time so it's time to shoot and our input dot get button down or let's see get button down for and i'm going to call it um bomb one so if bomb one is pressed then we'll return true otherwise we'll return so now we're checking our time and then we're checking to see if we press the bom one button there isn't a bom one button yet so we'll go set it up and then we'll make it well actually let's make it versatile now so that it works for player one and two so instead of bottom one we'll make it bomb plus player number or say player dot player number because i already exposed player number we'll just add the player up here in our awake which we don't have so just add an awake and we'll say player equals get component player because this is also just another component on our player class delete that private keyword and i'm going to turn it into an expression body method generate a field for the player just like that and delete out that private keyword and save then i think that's it so that should allow me to control whether or not i press the bom button or only fire when i press the bom button but i need to um hook up those inputs again so let's go back into our input manager we'll go to edit and then project settings and input and then in here we're just going to set up a bom one and a bomb too i'll show you how we set up buttons for the controller so right now we have a fire one down here and if you look at it it has fire one is the name of it and it's got a joystick button zero setup so this is kind of the def i think it's a square on this controller and it there's also a fire one up here if i expand it out for the keyboard that's the left click mouse 0 or left control this is the other way to fire so right now i can fire with this button but that's not what i want i don't want to use fire one i want to use something similar though so that i can control a bomb for player one and for player two so i'm actually going to just um let's let's duplicate out fire three so i'll duplicate the fire three element and rename it to bomb one with no spaces i almost put a space there now it's bomb one no spaces and look how it says joystick button two that is i i think it's going to be the circle button but i'm not completely sure and right now it's set up to read from all axes and it it's a little bit deceiving so i'm going to save hit play and then let's try dropping a bomb out so here we go i hit the button and a bomb dropped out you might have seen it right there i i just launched it out here let me see if i can move around and i hit the button oh is it time yet there we go and a bomb dropped out but watch this so this was the controller i'm moving on and if i hit the button on here after that bomb blows up bam i get another bomb so the problem i have is that right now it's reading from any controller now you might think to just go okay we'll just change this from all joysticks to joystick one because that's what i would do right but you dry it and it doesn't work it doesn't change anything it still reads from both of the joysticks right because it's it's it's not actually using that field for this what we actually need to change is this so instead of reading joystick button two we need joystick one button two now that will limit it to just reading from the first joystick again it's a little bit different because you don't use the joy number down here when we're on key or mouse button the joystick number doesn't actually do anything but now you can see i hit it and it doesn't do anything now on player two but on player one it actually drops the bomb again the part here that's interesting and important is really putting that joystick number there and still using key or mouse when you want to read a joystick button axes totally different which is kind of the weird thing and like on these controllers these buttons are axis so you know you're going to get mixed up a little bit don't worry about it but if you do just remember that you got to put the joystick number there all right so i'm going to stop playing go back in and make sure that these are set up right so i've got a joystick one button two and it's set up with the default set i'm going to duplicate it and make a bomb two name it oh name it bomb two and replace this joystick one with joystick two save and i'm gonna go into unity i'm gonna disable the default bomb that's right here i'm going to turn on my other player hit play and let's see my bomb launchers are releasing oh actually i'm going to go fix the word release right there and change my default sorry misspelled release and rename it ctrl r r e l e a s e velocity and i'm going to set the default here to something a little bit bigger like a 10 and save that off because the three was way way way too slow so now i just want to launch these bullets off and or these bombs off into the front and um you know what else i want to do i want to make them not collide with the players so let's do that first but i know i said i was going to do something else first but i'm going to make them not collide with the pictures i go to the bom script i'm going to change the layer of it right now it's on the default layer and everything is on the default layer so i'm going to add in two new layers i'm going to hit add layer i'm going to add in a bom and i'm going to add in a layer i'll go select the bom and i'm going to go to the layer section and choose bom and then i'm going to go to overrides and apply it so that all my bomb prefabs now have that if i hit select see that now the bomb is on that layer i'll go to my two players i'm gonna do it in prefab mode so i don't have to hit apply and i'll change their layer to player and then i'll hit yes to change the children too so it changes the collisions and save it off and if i go to project settings edit project settings and go to physics you'll see there's a collision matrix right here i can just uncheck the collision between bomb and player so player and bomb right there i can even uncheck player and players so they can stack on top of each other and maybe i'm going to leave bomb and bomb so they can bounce each other around i'll close that i'm going to file save project because that's the only way to save these things and then go back in and hit play by the way if you guys don't mind hitting the like button and the share button and all that stuff i really appreciate it i know i don't think i asked anybody about it yet but if you don't mind i i appreciate it it helps a lot um get stuff out there and you know it's cool all right so i'm dropping bombs on player two and dropping bombs on player one all right now the the next step is going to be obviously to actually next step is to make them drop bombs at each other first and then uh there we go their bombs bounce off now we'll make the bombs actually blow up the bad guys now we got two guys that can drop bombs we'll make them blow up bad guys and see who can get the most points all right so we'll stop playing actually let's see what this error is here oh this error by the way if you're looking at it and seeing it it's just a unity editor error it happens in uh this latest version of unity2020. i wouldn't worry about it it's nothing important all right so let's go make it do the actual exploding part where it blows stuff up when it when it actually blows up instead of just blinking and then disabling itself so go back into the script and what we want to do here is set up a damage radius like some range of distance that it can hit enemies at and then a damage amount so i'm going to add in two new fields actually let's do it in let's make the uh exploding part and it's not in the bomb because it's going to be in explode let's do it here and then we'll generate the fields for it so we've got our bomb script here it loops through waits until we hit the explode time and then at the end it does the damage by and destroys itself so let's implement doing damn first step is going to be to find all of the enemies in range so we can do that with a physics let's see if i can type it in p-h-y-s-i-c-s dot overlap sphere and then we can just give it our current position transform.position and then some radius let's call this explosion radius actually let's just call it radius so this is going to give us all of the colliders that are within the radius of our of this object right it's going to give us every collider that's within whatever our radius is of this position imagine there's a big giant circle anything that's within however many meters away this is will be returned back in this array of collider 2ds i don't have that yet so let's add it we'll go here and we'll say lighter not i said clyde or 2d it's a an array of colliders not clyde or duties let's say colliders so collider array named colliders is equal to physics.overlap sphere and we use our transform position and the radius let's generate a field for the radius hit f12 and go to it we'll replace private with serialized field again and i'm gonna make this like five meters away so this will get everything that's five meters away or or less and we can always adjust it it's a serialized field so we can modify it in the inspector all right i'll save that off and then what we want to do now is loop through all of these colliders and if any of them are enemies we'll just tell them to take damage so copy colliders and i'll say or each hit tab a couple times and i'll say enemy or actually let's say collider because enemy is not really accurate and hit tab again and put in colliders just pasted it so and then i hit enter so we're going to loop through each collider in the colliders and say bar enemy equals collider.git component enemy so this will get an enemy from that collider and then if there is an enemy on it so if the thing that we're overlapping into actually has an enemy script on it then we want to do something cool so the enemy dot take damage and we'll just make them take damage at um well whatever their position is we'll say enemy.transform.position and then we'll do the player number so we need to assign a player number to the bomb which means that we need to assign our bomb well we need to just let's just assign that on our bomb launch so say public and or let's do it how do i do this player number no public void set player and player number i say underscore player number equals player number ah type that wrong that one right there and generate a field for all i'm doing here is making a publicly accessible method to set my player number i could have just made it a public field too but i have a bad habit of not doing that and then we'll um yeah and then we'll assign it right here so we'll assign the player number what we're going to do the reason that i need to do this though is because this bomb is not going to be related to the player after it's launched so when i launch it i'm just going to set the player so when we do the player launching right here where's our part where we launch it on the bomb dropper when we drop the bomb i'll say bomb dot set player and we'll give it our player number do i have yeah i have the player here so player dot player number in fact i probably should just set the player and cash that or something but i think i'm good with it right now so we'll set the player lock that in that should allow us to give points to the correct player last thing i need to do is give it a damage amount oh actually we don't allow for damage amounts everything takes one damage so that's actually fine but let's fix that let's make it so that damage amounts can be bigger because right now only being able to do one damage is kind of lame let's make it so that we can do more so i'll say end amount equals one i'm gonna default the damage amount to one and i'm going to say the current health minus equals the amount so here in our take damage method of the enemy making it variable but optional so what this does by the way for anybody who's not used optional parameters is that we can um specify an amount and if we don't it will use one so when we call take damage it will have two overloads for it essentially let's go to the bomb and see what it looks like so here you'll see that my take damage is still fine even though i don't have a damage number but if i hit comma see it has end amount equals one i can just give it an amount so i'll say underscore damage i'll generate a field for it oops i generated a method i'm gonna hit control z type in damage again hit alt enter and i'm gonna generate a field instead i want a read only field for the damaged one there i'm going to go into take damage here because i think i might have generated an extra one yeah i did and when i hit f12 i generated a method that took object type for damage i'm going to just go in here and delete that and go back all right so save that off and then let's go back to our um call to take the image so in the take damage call in bomb we're passing in a damage amount now and i just need to go up here and set that up as a serialized field they serialize field damage equals let me give it a value of like five i think that's enough to kill everything i don't think we give anything more than five health so we'll save it off and let's go into unity and try out the bombs i expect my bombs are going to work unless i missed something i don't know if i missed anything let me know if you guys saw anything in chat yes i run around oh i need to turn on some enemies let's go find a spawner flip on this spawner that spawns guys from the bottom and start shooting and then drop some bombs i don't know oh yeah i don't know i don't know how good i'm going to do with this but i'm going to stop i'm going to turn on that spawner again while i'm not playing if this work go get the spawner on hit play i'm gonna grab player one all right and then we'll drop out a bomb ah i don't know if i okay i'm gonna have to turn off this other player i'm terrible at controlling two players at once downside to building a two-player game when you only got um two hands all right so i got marvin's coming in i'm gonna drop some bombs out there and see if the bombs actually do anything to them bam oh you saw that right the bomb just blew up both of those guys drop it out there the other thing i could do is just add like an on collision enter to the bomb too so that it blows up when it hits them but i think that just letting it roll out might be uh just just as interesting uh the radius is probably a little bit small it's kind of working though um all right i'm gonna stop playing and shut up for a minute so i don't know if there are any other features i want to add in real quick i guess maybe a a quick power up or something real quick and then i feel like i want to get over to building out to the arcade cabinet which is going to probably be i think i'll just do that in another one do another stream where we'll do the cabinet parking i need to set everything up so you can see how we set it all up to uh to run on there and build it out and then do one where we're going to um network multiplayer and do it online i want to get like a i think a working version up online so that you can play with it um and then go through and uh so like what i'm going through people can actually play the game online too and battle each other i think i might do that um sometime next sometime this week and go through that so somebody's saying can i disable the bots ai and put one as a test dummy um i mean we could the easiest way to disable them by the way is to just uh turn off their um their nav mesh agent they just make it so they don't move they won't walk oh just toggle that agent off they won't be able to move and they'll just stand still the other thing to do is crank up their health or make them invulnerable theoretically but um i don't think we need to but yeah you definitely could i said that's just on let's go to the box real quick go to the bots and go to the enemies you select them you just see the nab mesh agent here it controls their speed and it's how they move at different speeds you turn that off that'll just stand still you'll still be able to shoot them and kill them and stuff but it's stand still work fine as a dummy um let's see if there's anything else in chat i'm just gonna hang out and chat for a few minutes and see what everybody's up to too let me switch to camera view for a second pull things up and see what everybody's up to oh sorry you're really thirsty my dogs are going crazy outside barking at something knows what anyway um see i don't know if there's anything else yeah i think i might just wrap it up here and take a little break for a while and then we'll come back um maybe later this week go to either the cabinet side or the network multiplayer side i think things are separated out enough that it's um it's easy enough to switch it over to a network one and then it's also really easy to go to the cabinet so i don't know what you guys prefer if you want to see network stuff or arcade stuff my guess is probably network stuff but i don't know so if you guys have any preferences um can you just let me know and chat and i'll put up a poll on the community part of the page too and see what everybody thinks what they want to see if you guys have something there um preference there then you can go one way or the other um is there an issue with moving up and down arrow to move lines or just a preference um no i'd say there's there's definitely no issue using alt and up and down to move stuff um i use that a lot in writer too to block move things too um let's see what else network multiplier uh for the cabinet it's a arcade cabinet the nba jam arcade cabinet um i don't know if you can see it there there's some pictures of it but essentially building it out for multiplayer and i don't know this is kind of fun to put it onto there playing actual like uh unity games that you build onto a thing with with actual controllers and buttons is a blast obviously i think the network stuff applies to more people but it's um it's just not not nearly as exciting it takes a little bit more setup but it's it's still fun to do and it's pro it's pretty easy to do with a game like this we don't have a lot to cover so um it's relatively easy to handle so i maybe we'll do the network one next then we'll deal with bullets and uh bombs and all this stuff over the network and the replication and stuff that would probably be about the same amount i'm thinking probably about three hours to do a quick conversion into multiplayer just because things are already pretty easily separated out and ready to go it's going to be pretty simple to do but um yeah i don't know i feel like i'm just babbling now so it looks like everybody's up for the network stuff so i think i'll i'll probably go for that next and then maybe even just build out a full um a full tutorial too step by step or a little mini course or something on how to do it um outside of that i think i'm gonna wrap it up and take a break because i'm tired and thirsty and uh go do a bunch of other stuff got a couple lessons i need to finish encoding and export from course stuff and uh is there anything else i don't know i guess i just want to say thanks to everybody for coming out i really appreciate it it's always a blast um i'll put all of the code for this up to so you can grab it it's uh there's a link down below that has the code to start i'll put the latest version of the code up um after this call and then we'll go through uh and we'll just do the other stuff don't forget to hit like share subscribe and all that stuff we really appreciate it if you don't mind um go drop it on facebook or whatever else makes the streams fun and engaging and the lots of people in here so i appreciate it um and i don't know what else don't talk about anything else let me see anything else to talk about oh i was a little curious i mean i i don't know if this right place asked but i was curious about the other video stuff was doing so i did a video on a desk review that was totally not code stuff and i didn't know if anybody um hated it it seems like it's actually doing okay though i was thinking about doing one on um this chair specifically ergonomically i really love this razer isker chair it's freaking amazing i was really excited when it came out because it has lumbar support and it it's helped my back on so if people are interested in that kind of stuff too let me know um i'll i'll do some more of those too i'll probably do them anyway just because they're fun um and it lets me practice playing with the camera a little bit anyway um i think i'm out of stuff so i just want to say thanks again don't forget to like and subscribe and all that stuff and then uh if you want to see us go to networked multiplayer well it'll be in mirror we'll do it with mirror and we'll um convert everything over to running on the network and i'll even get a webgl version up and running first so that people can actually try it out play it go through the code and stuff um again you have to get your own art but eventually i'll get some art that i can just distribute and then build out a full um like a full tutorial that you can mark you can download and stuff and try things out so oh thanks again everybody for coming out and watching i really appreciate it again don't forget to hit hit share and all that stuff that makes i think a bigger difference or just leave a comment afterward if you liked it or anything appreciate it again all right i'm gonna shut up now and hit the end button and
Info
Channel: Jason Weimann
Views: 17,604
Rating: undefined out of 5
Keywords:
Id: 9BJln8dytMM
Channel Id: undefined
Length: 112min 34sec (6754 seconds)
Published: Tue Nov 24 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.