Project Description


Title: Making a Multiplayer FPS in Unity – Part 1
Platform: Unity Tutorial
Length: 19:57
Difficulty: Intermediate

In this video we set up our Player and begin moving him around.
● Download project (GitHub):


Learn how to make a multiplayer first-person shooter in Unity. This series teaches the very cool Unity Networking system (uNet). All code is written entirely in C#.

Thanks for tuning in that bracket keys and i want to welcome to the first video on creating a multiplayer FPS and unity so this is the subject with Kristen 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 of going you can go to breakfast , 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 . 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’re going to be making and I don’t know how much of it we’re 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 used for testing some stuff out and this is the actual player and I know that he looks kind of funny but I was picture thinking that we could make this kind of sci-fi like and make him some kind of a sphere ‘ish robot with the thruster down here and i have the weapon rotate around this fear and therefore because he’s kind of levitating in the air while we play I’ve made the controls are almost spring like and I’ve made him a gift game giving him the ability to fly so we have these thrust of force and fuel and region speed and controls down here and you can see that I’ve created a player motor and a playercontroller 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 play here and drag the game over here that 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 smooth 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 run out of thrusters 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 any other FPS cool you can of course use this tutorial for creating a completely ordinary first person character but then you might as well use to standard assets one cool so let’s go ahead and close down that project and I’ve created before hand 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 group’s 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 x 64 and drag it in here and let’s also take a couple of cubes maybe the four-by-four 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 two groups is that bigger that’s a lot nope it’s just being placed play strongly 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 re and 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 UH 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 and 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 the lead 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 the scene here so I’m just going to call this main level one so fire because we don’t know what this is actually going to be doing it cool so let’s start building our player so we’re going to start completely from scratch and we’re going to do so using a a sphere so that’s right click on this going to game objects or 3d objects fear reset the transform on that and let’s set the position on the y-axis 21 and this looks nice already and let’s go ahead and breathe move the mesh renderer and Dinesh 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 week weight and create a novice fear i removed we remove the collider on this so this way we have the graphic separated from the collider and we can move those separately that’s just a nice thing to do so we can call this layer model here and this is of course temporary and then this fear 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 a 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 are player is facing that’s go ahead and create a temporary gun model under this camera so that’s it right click go into 3d objects like cube let’s give this a cool dark into material so let’s go down here right click create material and that’s called this week on material for now and let’s change the albedo to a greater greater 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 a shot ok 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 another empty object we said that that’s called this one gun and let’s drag the cube under that gone object we can then move this out and then we can start modeling our guns 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 rigid body on our player are rude object here and we can set the mass to one that’s fine i do want some drag but we’re going to leave it at zero 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 stuffing our scene when it comes to position then we want to uncheck use gravity because we want this guy to be floating and we’re going to make the nice bounciness using some kind of spring component but that’s something that will add in later so this should be the basic setup for our rigid body 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 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 well what we should we be looking and then we have the motor which simply has a set of functions which will move move the player making jump and making 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 rigid body so that’s kind of the way you should look at these two scripts you have to control their 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 our monodevelop which i do recommend that you do then go under added and then references external tools and choose visual studio 2015 and if it’s not there you can browse for it cool so it’s opening up on visual studio here and should be ready in just a second 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 to 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 kind of 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 on move but first off let’s look over in the player controller well the player controller you can delete that – it’s 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 rigid body we we’ve already added a rigid body 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 the actual movement so we can start out by making a serialize field private float called speed and said this to something like 10 or maybe five it’s going to be fine and if you don’t know marking something serialize field but basically make it show up in the inspector even though it’s set to private so this is the exact same as during public serialize field even though it’s still there but it’s still protected 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 will just said 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 Lord 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 f load 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 lurking 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 acces well then unity is going to perform some processing on it and you won’t be in full control so by default let’s get the raw axis and then let’s perform my own smoothing later and the access that we want to get here is the horizontal axis then we want another flowed and will call the sea and the move and we’ll set this to input . get access raw and then vertical and of course the access that we are axis we are getting here i set up inside of unity so if you’re going here going to edit project settings input axis and you can see here that we have the horizontal and the vertical that’s why we’re getting these from and if you’re not aware whenever we use a keyboard or a 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 of movement on the two axes then we’re going to create a better 3 i’m going to call this move horizontal and we’re going to set it equal to transform . right that’s going to be our direction to the right but this is going to be our local so when using transformed ride instead of a vector3 dried will take into consideration our current rotation which way we are facing and it won’t just be relative to the world so transformed uh dried and then we will multiply this by our X movement and we’re going to do the same negative vector here called move vertical set it equal to transform . forward so this is our forward movement and we’re going to set that equal to or multiply that with our see movement so transformed that right is a vector with the values 0 1 comma 0 comments 0 and the transformed forward is a vector with r 0 comments 0 , 1 and then we multiply this value into it so if we don’t move it all this is going to be 0 0 0 if we’re moving forward then this is going to be 100 and if we’re moving backwards this is going to be – 00 so r – 10 surround the same down here so this is just the value that’s going to change so if we’re not moving if we’re 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 a local velocity vector and then we can combine these two into our final velocity vector and we’re going to simply are combined them by saying move horizontal plus of vertical and then we’re going to normalize them and multiply them oops multiply them by speed variable so what we’re doing here is we’re combining the two when normalizing we’re 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 want get a varying speed when multiplying these will always get a vector with the length of one and that basically means that we are only using this acid direction that we then multiply with the speed called 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 but just called this function move and will 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 than 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 enjoyed this one who fed all and I’ll uploaded as soon as I can I’ll see you in the next video.