Making a Multiplayer FPS in Unity (EP. 1) - uNet Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Brackeys is my savior

👍︎︎ 8 👤︎︎ u/SwahjerDev 📅︎︎ Oct 05 2015 🗫︎ replies

I watched the Brackeys series on making pong and honestly thought that is was very informative and did a great job at teaching Unity 2d for a beginner. I was very thankful to stumble across it. I looked at using more of their series to lean more but decided to look at other resources so I could work at my own pace. It seemed like the subject matter that I was interested in had tutorial series that were not yet finished and within a matter of lessons I would have to wait for the next ones to come out before finishing the project. When the whole series is done I will defiantly check them out. Great stuff.

👍︎︎ 3 👤︎︎ u/Thetrav1sty 📅︎︎ Oct 05 2015 🗫︎ replies

Keep it up. Gonna keep an eye on this

👍︎︎ 6 👤︎︎ u/Keirron 📅︎︎ Oct 05 2015 🗫︎ replies

His voice is really good, I could listen to him whilst trying to get to sleep.

👍︎︎ 3 👤︎︎ u/pinyinyangyang 📅︎︎ Oct 05 2015 🗫︎ replies

Based on first episode impression these http://forum.unity3d.com/threads/unity-5-unet-multiplayer-tutorials-making-a-basic-survival-co-op.325692/ are probably a better choice if you want to learn the networking part more so than the generic coding.

👍︎︎ 2 👤︎︎ u/[deleted] 📅︎︎ Oct 05 2015 🗫︎ replies
Captions
thanks for tuning in at brakus hello and welcome to the first video on creating a multiplayer FPS in unity so this is the subject requested by so many of you guys and I thought I would finally go ahead and cover this in a series and it's a great time to do so because unity quite recently released a unit or unity networking which is their new networking solution and I can tell you it's it's actually pretty great so that's what we're going to be doing and we're going to be creating the game in c-sharp and I do expect you to have some understanding of basic unity concepts and programming concepts but that being said I will explain a lot of stuff along the way as much as possible cool so before we go ahead and get started with today's video which is setting up our player and the player controls I just quickly want to mention that if you want to support me and the series and the other series I've going you can go to break is calm and I do have a donate button here it helps out a lot and keeps me going and also if you have any questions throughout this course I suggest you go to forum practice comm where you can make a post or a topic here and you will almost certainly get some answers cool so I just quickly want to give you a taste of what it is we are going to be making and I don't know how much of it we are going to be able to cover in this first video but you can see here I've made this test scene and this is just a project I use for testing some stuff out and this is the actual player and I know that he looks kind of funny but I was pictured thinking that we could make this kind of sci-fi like and make him some kind of Spheeris robot with a thruster down here and I have the weapon rotate around this sphere and therefore because he's kind of levitating in the air while we play I've made the controls almost spring-like and I've made him a gift given him the ability to fly so we have these thrusts of force and fuel and reagent speed and controls down here and you can see that I've created a player motor and a player controller script which which actually controls his movement so that's what we're going to be looking at today and if I go ahead and hit play here and drag the game over here so you can see what's happening to the controller you can see that we can look around like this we can also of course move around and this is not smoothed out yet that's something we can do in a in a future video and then you can see that I can fly away here and when I ran out of thruster I simply fall to the ground and you can see just how smooth that is when I use the thrusters here and that's something you can completely control how how much dampening and spring effect you want on that but I think this should give some really cool controls that are not just like in yadi fps cool you can of course use this tutorial for creating a completely ordinary first-person a character but then you might as well use the standard assets one cool so let's go ahead and close down that project and I've created beforehand here a new one called multiplayer FPS it's an completely empty project and I just set the defaults to 3d and in here you can see I have an empty project folder so let's go ahead and right click on that import package and then environment and this will just allow us to use some of the whoops not an environment that was wrong import package prototyping because a unity has some quite nice prototyping prefabs like the floor plane and some of the cubes that you saw me using and you can see that if you go under standard assets prototyping models there are a lot of different stuff that we can use here so let's just take the big floor prototype the 64 by 64 and drag it in here and let's also take a couple of cubes maybe the 4 by 4 ones and just place them on the ground so let's just place one there duplicated move one over here let's take a smaller one - oops it's not bigger that's a lot nope it's just being placed placed wrongly so let's just drag it in here and reset the transform there we go and we can just drag it over here just so we have something to orient ourselves in the scene and right now all of the colors here are fairly boring and that's something we can change soon for now let's just get cracking on the our player controls so up here let's create an empty game object let's reset the transform on this and let's call this underscore environment you don't need the underscore here it's just a habit of mine whenever I create these kind of grouping objects but actually let's just go ahead and delete that that's unnecessarily confusing and let's just take all of this stuff including the light and drag it under there so now we have this clean hierarchy up here and the main camera which we are going to just delete because we're going to be creating one for the player instead and because I excessively save all of my scenes let's press ctrl s and just I save this scene here so I'm just going to call this main level one so far because we don't know what this is actually going to be doing yet cool so let's start building our player so we are going to start completely from scratch and we are going to do so using a a sphere so let's right click on this go and do game objects or 3d object sphere reset the transform on that and let's set the position on the y-axis to one and this looks nice already and let's go ahead and Bri move the mesh renderer and the mesh sphere here and let's create another object under this an empty object again make sure that's reset let's rename this to graphics and under this we create and create a nother sphere I remove we remove the collider on this so this way we have the graphics separated from the collider and we can move those separately that's just a nice thing to do so we can call this player model here and this is of course temporary and then the sphere here we can go ahead and call player awesome so we're going to need a bunch of stuff on this player first off we're going to need a camera so let's just create a camera object and that's going to sit inside of our sphere so just reset the transform on that and that should be fine and and this has all of the default settings which are going to be fine for now and so that we know which way our player is facing let's go ahead and create a temporary gun model under this camera so that's it right click go on the 3d object select cube let's give this a cool darkened material so let's go down here right-click create material and let's call this week on material for now and let's change the albedo to a greater grayer color here and drag it oops make sure you drag it onto the cube here like this and let's make it kind of dark and that should be just fine and the smoothness here I'm going to drag all the way down so that this isn't shine okay we can give it a bit of shine there that looks fine and we can go ahead and rename this actually let's create another object here and not the empty object reset that that's called this one gun and let's drag the cube under that gun object we can then move this out and then we can start modeling our gun here awesome so now that we have that in place we can go ahead and actually create some logic for our player because not right now when we play the game of course nothing is going to happen whatsoever so we can start out by creating a rigidbody on our player or root object here and we can set the mass to 1 that's fine I do want some drag but we're going to leave it at 0 and then I'll show you what drag does later so constraints we're going to freeze all of the rotation because that's only going to be driven about by our mouse but I don't want to freeze the position because I want to be able to be affected by stuff in our scene when it comes to position then we want to uncheck use gravity because we want this guy to be floating and we are going to make the nice bounciness using some kind of spring component but that's something that we'll add in later so this should be the basic setup for our rigidbody and then I want to make two scripts so the first one is going to be our player motor new scripts of type C sharp and the second one is going to be on player controller so when it comes to movement there is a million ways of doing things and I've tried here to find a nice balance between optimization and readability so when it comes to like thinking about how we want this a movement to work I think it's logically a great idea to split it up into two scripts we have the controller which handles all of the input and stuff like how much fuel is left is we are we jumping or what way should we be looking and then we have the motor which simply has a set of functions which will move move the player make him jump and make him fly all of that so that doesn't handle any of the actual input it's just kind of you could call it a utility script that will take directions and velocities and all that and apply them to the richer body so that's kind of the way you should look at these two scripts you have the controller and the actual motor that drives it and if we go ahead and double click on these it's going to open up in visual studio and yes I'm using Visual Studio it's something that comes with unity now and if you want to be using Visual Studio instead of monodevelop which I do recommend that you do then go under edit then preferences external tools and choose Visual Studio 2015 and if it's not there you can browse for it cool so it's opening up Visual Studio here and should be ready in just a second and there we go it loaded on my other screen and let's just load up the player controller - so we have these two right here I'm just going to close the scripting API so the player motor is going to require a component type of rigid body because we want to always have a rigid body with our item player motor I'm also going to delete that using statement there because it's not needed and in here we are going to have some methods for actually making our player move but first off let's look over in the player controller well the player controller you can delete that too is going to require another component and this is going to require type of player motor so when adding a player controller it's going to add a player motor which is going to add a rigidbody we've already added a rigidbody but just in case it's a good idea to do it like that awesome so the first thing that we are going to be creating here is on the actual movement so we can start by making a serialized field private float called speed and set this to something like ten or maybe five it's going to be fine and if you don't know marking something as serialize field will basically make it show up in the inspector even though it's set to private so this is the exact same as doing public serialize field even though it's still but it's still protected so it so that's really good so then we can make a private reference to our player motor and we'll just call this motor and we can set this in the start method we'll just set motor equal to get component player motor and this is where the required component is really awesome because we don't have to do any checking or error handling we know that there's going to be a player motor on this game object then inside of our update method word update we are simply going to calculate our movement velocity as a 3d vector so basically we're first going to get our horizontal movement so we're going to store that as a float and let's just call this X move and the underscore here is of course optional I just like to do this with variables creating created within a method so X movement is going to be equal to input get axis and I'm going to choose get access wrong because I want to do our Milo looping on my own so if we want any kind of smoothing here it's good to be in complete control on of how we do that and if you use get axis well then a unity is going to perform some processing on it and you want being full control so by default let's get the raw axis and then let's perform our own smoothing lay and the access that we want to get here is the horizontal axis then we want another float and we will call the C and the move and we'll set this to input that get access raw and then vertical and of course the axis that we are axes we are getting here I set up inside of unity so if we go in here go into edit project settings input axis and you can see here that we have the horizontal and the vertical so that's where we are getting these from and if you're not aware whenever we use a keyboard or controller horizontal is going to go between minus 1 and 1 and vertical is going to also go between minus 1 and 1 so we can use those to do perform live movement on the two axes then we are going to create a vector 3 I'm going to call this move horizontal and we're going to set it equal to transform dot right that's going to be our direction to the right but this is going to be a local so when using transform that right instead of vector 3 right we'll take into consideration our current rotation which way we are facing and it won't just be relative to the world so transform right and then we'll multiply this by our X movement and we're going to do the same make a vector here called move vertical set it equal to transform dot forward so this is our forward movement and we are going to set that equal to or multiply that with our see movement so transform that right is a vector with the values 0 1 comma 0 comma 0 and the transform dot forward is a vector with a 0 comma 0 comma one and then we multiply this value into it so if we don't move at all this is going to be zero zero zero if we're moving forward then this is going to be one zero zero and if we're moving backwards this is going to be minus zero zero so our minus one zero zero and the same down here so this is just the value that's going to change so if we are not moving if we are moving and if we are moving backwards that's the result of this calculation so we can use this quite effectively to get kind of our local direction or our local velocity vector and then we can compile these two into our final velocity vector and we're going to simply combine them by saying move horizontally plus above vertical and then we are going to normalize them and multiply them oops multiply them by eye speed variable so what we are doing here is we are combining the two when normalizing we are saying that well the length of these shouldn't matter so when we are combining them we are saying that the total length of this combined vector should be one and that means that we won't get a varying speed when multiplying these we will always get a vector with the length of one and that basically means that we are only using this as a direction that we then multiply with the speed cool and then we apply this movement so this is going to be our final movement vector and then we apply our movement and we do this by calling some kind of function on the motor and we're going to make this in a second and we'll just call this function move and we'll pass in the velocity vector so now we can jump over to a player motor and actually make this happen so the video kind of went on for a lot longer then I had expected so I'm sorry but I have to cut this up into two parts I hope that you will enjoy the next one as much as you've enjoyed this one you fed all and I'll upload it as soon as I can I'll see you in the next video
Info
Channel: Brackeys
Views: 1,595,680
Rating: undefined out of 5
Keywords: unity, unity3d, tutorial, material, materials, beginner, and, settings, how, to, howto, learn, learning, course, series, tutorials, workflow, game, development, develop, games, programming, coding, basic, basics, C#, intermediate, uNet, unity networking, networking, multiplayer, FPS, first, person, shooter, first-person shooter, movement, controls, player, character, custom, brackeys, making, unity tutorial, ep 1, episode 1, unity fps
Id: UK57qdq_lak
Channel Id: undefined
Length: 19min 57sec (1197 seconds)
Published: Sun Oct 04 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.