Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GTGD's Unity Multiplayer Tutorials

Discussion in 'Community Learning & Teaching' started by GTGD, Feb 7, 2012.

?

Please select each option you agree with (you can select multiple options)

Poll closed Dec 22, 2015.
  1. I like that the videos are covering a complete project.

    230 vote(s)
    88.1%
  2. I find the videos are detailed enough for me to understand and follow.

    197 vote(s)
    75.5%
  3. I find the video quality is clear enough.

    186 vote(s)
    71.3%
  4. I find the audio quality is clear enough.

    180 vote(s)
    69.0%
  5. The narrator doesn't send me to sleep.

    143 vote(s)
    54.8%
  6. In general the topics covered are interesting.

    170 vote(s)
    65.1%
  7. I find the website useful.

    130 vote(s)
    49.8%
  8. The Gamer To Game Developer logo looks good.

    119 vote(s)
    45.6%
  9. I would like to suggest topics that GTGD should cover in the future.

    103 vote(s)
    39.5%
Multiple votes are allowed.
  1. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Welcome! I've made a new Series 1 showing how to make a multiplayer game using Unity 2017. S1 is aimed at intermediate devs and the complete S1 is only available on Steam and includes all videos and project folders.

    I cover the following topics:
    1. How to use the default Network Manager to create Direct Connection (LAN Games) and Match Maker (Public Games). Note that Unity’s match making service is a paid service and once a developer exceeds the free concurrent user count, the developer has to pay for additional concurrent users.
    2. How to write your own Custom Network Manager so you are not reliant on the default HUD and Network Manager. You will create Direct Connection and Match Maker (Public) games.
    3. Enable your Custom Network Manager to allow for multiple player prefabs and being able to select scenes.
    4. How to use Commands, ClientRPC, and Syncvar with hook function.
    5. How to use the Network Transform and Network Animator components.
    6. How to sync fundamental game mechanics such as; shooting, health and damage.
    7. How to implement network chatting.
    8. How to implement networked AI movement.


    S2 is only available on Steam and is aimed at intermediate devs wanting to see how to setup their own master server and other stuff like syncing animation smoothly across the network. S2 was made in Unity 4 so it is really out of date now. I'm planning a new project to replace the old one on Steam.


    S3 for Unity 5 is a major FPS tutorial series covering a wide range of systems, including inventory, object destruction, NPC AI, vehicles the player can drive, etc. It is single player only. S3 is aimed at devs who are completely new to Unity and coding. The complete series is available on YouTube and also on Steam. The Steam edition includes the project folders.


    I have a website at http://www.gamertogamedeveloper.com/. I also have a facebook page. I'm inviting everyone to join the GTGD S3 Steam community group.

    Oh and don't forget to subscribe to my YouTube channel and become more than a gamer!
     
    Last edited: Nov 23, 2017
    DarkForceLeader and jebi like this.
  2. zOrigin

    zOrigin

    Joined:
    Jul 31, 2010
    Posts:
    21
    Awesome GTGD
     
  3. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Thanks a lot.
     
  4. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thank you. I've released three videos so far and I'm a few days away from releasing video 4 where we'll start building the multiplayer system. Please feel free to leave any feedback to help me improve subsequent videos. I have been told that I sound a bit robotic so I'll be working on that.
     
  5. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I've just released Video 4 and I had to go into overdrive to release it in such a short time. Video 4 is where we'll establish our multiplayer system and this is what we were all waiting to see and I just couldn't leave you hanging any longer. It's a big video and is one of the most important in this series. From Video 4 onwards our series 1 will become more and more interesting. So stay tuned.
     
    Last edited: Feb 11, 2012
  6. modulo

    modulo

    Joined:
    Sep 10, 2011
    Posts:
    31
    thank you I will follow this tutorial
     
  7. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Just a quick update. I'm aiming to publish Video 5 "Our Spawn System" by Thursday the 16th of February. In that video we will write the SpawnScript, setup spawn points, setup blue team and red team, reconfigure our player for multiplayer, and deal with locking and unlocking the mouse cursor.
     
  8. modulo

    modulo

    Joined:
    Sep 10, 2011
    Posts:
    31
    MultiplayerScript ok this is the best tutorial for the multiplayer
     
  9. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thank you, I've just uploaded video 5 Our Spawn System.
     
  10. lockbox

    lockbox

    Joined:
    Feb 10, 2012
    Posts:
    519
    Thank you so much for putting out this video series! I'm only up to video two, but I'm really impressed.

    The preview of the game in video one really got me excited about watching the series. There are things in the game that I can use for my own project, that I'm sure others can use as well. I think the pace is just right, I have no problems with sound of your voice and everything you're pointing out is really helpful. You are very comprehensive, and I really appreciate every little detail - but perhaps that's just me. lol

    This is really fantastic! You're going to save me a lot of time in getting my prototype multiplayer game up and running.
     
    Last edited: Feb 15, 2012
  11. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    You're welcome and I really do hope that it helps with your project! Someday when you've completed your prototype multiplayer project please do drop us all a link, and if you ever find that the going gets tough for you then don't get discouraged or give up, because that is precisely when you're about to overcome the challenge.
     
  12. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I’m working on Video 6 Health Damage System and I’m aiming to release it by no later than the 23rd of February. Hit detection in multiplayer is much more complex than hit detection in single player and in the upcoming video I’ll be showing you step by step how to build a solid hit detection and damage application system that will work even when the ping of some players is high.

    In Video 6 we will do a lot!
    • We will write our own class, and setup a PlayerList that uses our class to store vital information about each player and this list will be kept uptodate across the network.
    • Write a PlayerName script to manage the player’s name across the network.
    • Write our HealthAndDamage script to handle damage application and the player’s health, and we will write it in a way that gives us solid damage application, so that an attacking player is unlikely to experience a situation where they are shooting at an enemy but their hits are not registering.
    • Update our FireBlaster and BlasterScripts so that our blaster projectile can damage and destroy enemy players.
    I'm expecting that this video will be well over two hours in length, so thanks for your patience :D.
     
  13. lockbox

    lockbox

    Joined:
    Feb 10, 2012
    Posts:
    519
    No worries. I've been having fun building the game as I watch, which takes a bit longer than the video itself. Wish I had more hours in the day. I'm currently in the middle of video 4 and should be caught up by Monday. Good stuff!
     
  14. Ebkac

    Ebkac

    Joined:
    Feb 3, 2012
    Posts:
    62
    Thank you for the well documented code. As I'm really new to programming and Unity, (like 3 weeks new), having you walk through what each line is doing and what each of the pieces inside said line of code is actually doing helps me out tons.

    I also like how you focus on gameplay and now graphics.

    One final item. Try not to feel pressure to meet deadlines to get them out in X time. I can't speak for everyone here, but I think most of us will take quality over quantity!
     
  15. lockbox

    lockbox

    Joined:
    Feb 10, 2012
    Posts:
    519
  16. madmaxmon

    madmaxmon

    Joined:
    Oct 7, 2010
    Posts:
    19
    Good stuff. Not looked yet but I certainly will.

    It might be worthwhile updating the original post as well, and put AVAILABLE or similar next to the ones that are ready.

    Thankyou.
     
  17. Ebkac

    Ebkac

    Joined:
    Feb 3, 2012
    Posts:
    62
    Good evening. I'm working through your lessons and have been able to reproduce them so far, (up to video 3).

    I'm going back through what I wrote following the lessons and really trying to understand the syntax and for lack of a better term, "what" I am typing. I've been using the command ' trick highlighting words and reviewing the docs online and this is what I have come up with so far.

    If the author or others reading this post has time to review my comments, I'd appreciate having any errors pointed out to me or perhaps better ways to phrase my statements to make them clearer.


    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. /// <summary>
    5. /// This script is attached to the player
    6. /// and it causes the main camera to continuously
    7. /// follow the CameraHead GameObject
    8. /// </summary>
    9.  
    10. public class CameraScript : MonoBehaviour {
    11.    
    12.    
    13.     // variables start ______
    14.    
    15.     // create a new variable called myCamera and set the "type" to Camera
    16.     private Camera myCamera;
    17.    
    18.     // create a new variable called cameraHeadTransform and set the "type" to Transform
    19.     private Transform cameraHeadTransform;
    20.    
    21.     // variables end ______
    22.    
    23.    
    24.     // Use this for initialization
    25.     void Start ()
    26.     {
    27.         // link the variable to a specific camera in the scence, the "main" camera in this case
    28.         // reading: variable myCamera is equal to a "generic camera" and then the specific camera in the scene
    29.         myCamera = Camera.main;
    30.        
    31.         // link the variable to a specific GameObject in the scence, the CameraHead GameObject in this case
    32.         // reading: variable cameraHeadTransform is equal to the position of the Game Object CameraHead
    33.         cameraHeadTransform = transform.FindChild("CameraHead");
    34.     }
    35.    
    36.     // Update is called once per frame
    37.     void Update ()
    38.     {
    39.         // Make the main camera in the scene follow the position
    40.         // and rotation of the CameraHead GameObject
    41.         // reading: variable myCamera's position in the scene is equal to the position of the variable cameraHeadTransform
    42.         myCamera.transform.position = cameraHeadTransform.position;
    43.        
    44.         // reading: variable myCamera's rotation in the scene is equal to the rotation of the variable cameraHeadTransform     
    45.         myCamera.transform.rotation = cameraHeadTransform.rotation;
    46.     }
    47. }
     
  18. GizmoMKD

    GizmoMKD

    Joined:
    Feb 12, 2011
    Posts:
    13
    Good tutorials, thank you.
     
  19. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I've just released video 6 where we implement our Health and Damage System and this video is super important for our prototype game! Thanks for all the helpful feedback everyone and I'll try and reply to your messages and comments as and when I get enough time.
     
  20. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thank you so much for posting a link to this tutorial! It is really outstanding and if you find other tutorials out there like this one then please let us all know about it. I believe it would be a really good idea to make use of the Unity Master Server in the next series for Gamer To Game Developer.
     
  21. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I've had a good read through of your script and it took me a little while to make sense of what you meant by "reading", but I'm guessing that you mean that the compiler is reading that instruction in the script (my knowledge of that is limited). There's nothing wrong with your script and if the comments make sense to you now, and in the future, then that is what's important. If you want, you could even explain in the summary area what is meant by the term reading or any other terms that you may use in the future.

    Your script looks neat and tidy and I found it very easy and pleasant to read the code.


     
  22. Merries

    Merries

    Joined:
    Feb 2, 2009
    Posts:
    262
    Very very nice series thank you for putting this up. Put up a donation box so we can offer some hamburger money :) Also will you be putting in 3rd person perspective with this series? I hope so.
     
  23. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks Merries, I hadn't implemented a 3rd person perspective in series 1, but it will be fun to implement so what I'll do is to add it as an additional video at the end of series 1. So now we'll have 35 videos instead of the original 34 that I planned, and your request will be video 35. You'll have to wait several months while I roll out series 1 :).

    Rather than a plain donate button I might make an exclusive, non essential, video available for sale when I've published most of series 1.

     
  24. Ebkac

    Ebkac

    Joined:
    Feb 3, 2012
    Posts:
    62
    GTGD,

    Thanks for the reply. My intention with the "reading" line is to try to verbally describe what each piece of the code is actually doing. Saying
    Code (csharp):
    1. "// The following code makes the camera rotate"
    is great, but I struggle to identify what each of the sections of the code actually are doing.

    Hence my attempt to explain the sections of the code using written words for each dot notation piece.

    You by far have the best comments I've come across for tutorials, so a big thanks for that as it helps us new users out a lot.
     
  25. pixelsteam

    pixelsteam

    Joined:
    May 1, 2009
    Posts:
    924
    Very impressive work, I will follow!
     
  26. eiwer

    eiwer

    Joined:
    Sep 26, 2011
    Posts:
    23
    thank you so much for making a great tutorial, amazing one! your voice is pretty good :p and I guess it's American accent? will get my english improved throughout the tutorial as well ^^

    as I was quite a novice for programming, I think it's better for me to learn from this tutorial and start coding on my own game later. I'll focus on only making project assets until then.

    great job, keep it up! :razz:
     
  27. qatar1983

    qatar1983

    Joined:
    Feb 21, 2012
    Posts:
    5
    10/10 the sound
    10/10 the exploitation
    3/10 i can't wait the next show

    good start and thank you for it
     
  28. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks! I think you meant explanation rather than exploitation :)

     
  29. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks for the support Eiwer, and I hope that you find this tutorial series will help you in learning more programming so that you can build your game. I'm going to have to take more care with my usage of English so that I don't start spreading any bad habits :p.

     
  30. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I've just published Video 7 Respawn Player Identity!
     
  31. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,254
    Thank you so much for taking the time to record these!
    I've only watched video 4 for about half an hour so far, but I already see a great resource for many developers around here.

    My next project will include multiplayer functionality and I only did some of the basics (RPCs, movement sync), with your help I will deepen my knowledge. And.. most of your videos are longer than 2 hours, they should cover everything everybody ever need. Much appreciated!
     
  32. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks Baroni, I can't say that I'll cover everything that anyone would ever need, with respect to multiplayer, but I will certainly be covering a lot! I'm hoping that developers following the series will gain a solid foundation in Unity multiplayer scripting, so that they'll find it much easier to build their own projects. The more that I learn the more I realize how much I actually don't know and there's so much more scripting that I have yet to learn, and that's a good thing! :D
     
  33. Squatsh

    Squatsh

    Joined:
    Mar 4, 2012
    Posts:
    2
    Hey GTGD i have gone through all 7 videos over the weekend. and i think the tutorials are amazing,i like the style and big thumbs up on pronunciation, clear easy to understand speech is rare in video tutorials.Assuming you spend about 1.5* the length of the video, in time making it. I would have a probably bit more time during weekdays to spend on Unity which is understandable everyones job/life is different.

    So I am going to add some things like,headshot (and torsoshot,armshot,legshot etc.), different weapons and other less coding intense things that i know how to add to your scripts since i am not so good at coding yet. My question is, is there anything coming up in future vids that comes to mind that might easily produce a problem depending on the things i implement (its not limited to the examples) and yes i am kinda asking for a sneak peek, hehe. Also do you have a ETA when the series will be done. No rush though just curious because i like to plan out what i do ,before i do it hehe.

    Great Job so far :D
     
  34. OmniverseProduct

    OmniverseProduct

    Joined:
    Feb 26, 2012
    Posts:
    1,568
    I'll admit to being skeptical about these tutorials. I honestly thought it just another set of tutorials when I say the thread title. When I get more scripting knowledge down, I'll try these out and see if I'm wrong, but not right now.

    I thought that because of the thread title. I thought it was just another group of people making a tutorial. In all honesty, I still do. I hope you don't take offense to any of that.

    Btw, what scripting language do the tutorials start out using?
     
    Last edited: Mar 4, 2012
  35. ChaosMax

    ChaosMax

    Joined:
    Jun 23, 2010
    Posts:
    21
    Just watch the video in the first post dude that will show you what the tutorials are about. Its like an overview.

    Language is C#
     
  36. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks for the feedback Squatsh! You watched all 7 videos over a weekend!

    I'm pretty sure you can add what you're intending without breaking the project for the future videos, though I'd suggest making a backup of the project files just in case.

    I actually have a rough idea of how I would go about implementing torsoshot, armshot, etc. and what I imagined is using a bunch of colliders to represent each of those and to have a script attached to them that will simply pass on the damage message (attacker name, weapon type, shot modifier) to the main HealthAndDamage script. I'd imagine that I would use the HealthAndDamage script as the torso script and it would remain the main script for managing the players health. I would also keep the torso tag and collider the same as our Trigger collider (so the Trigger collider is the torso).

    The HealthAndDamage script would probably need to be modified a little bit so that those other scripts, on those new colliders, could tell the HealthAndDamage script to apply a modifier depending on the type of shot. I will be implementing the area of effect rocket later on, in this series 1, and that could get a little tricky because it would see all the colliders so it might pay off for you to give the new colliders a different tag from the torso collider so that way only the torso collider would be recognised in area of effect damage application.

    At my current rate of progress I might not be done with all the videos until May or June but that could change after video 10 because videos 3 to 10 are the main videos in this series and are the really long ones. The longest videos after that I think will have to do with the Construction Block and Air Block because of the large amount of scripting involved. The truth is that for each hour of video you watch it takes me about 3.5 hours to produce and that time consists of recording the video and then editing it.

    Btw, when you do have your system worked out and functioning please do put in a video or a couple of screen shots of what you achieved in this forum thread. I'm sure a lot of viewers would be interested.

     
  37. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks ChaosMax, I couldn't have put that more concisely. When I saw OmniverseProductions post I was :confused: and no I didn't take offense to his post.

     
  38. justintmetal

    justintmetal

    Joined:
    Mar 6, 2012
    Posts:
    2
    Hello,

    I think this set of tutorials are really great and they are helping me to better understand scripting in C# and how unity works but I've run into a problem on the third tutorial with the FireBlaster script. The problem I think is with the word Instantiate at the end of the code because whenever I take that bit out, nothing else is wrong with the script. Please someone have a look at it and maybe tell me what I'm doing wrong.

    Thanks in advance!
    -Justin

    Here is the script I have written following the tutorial:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. /// <summary>
    5. /// This script is attached to the player and allows
    6. /// them to fire the Blaster projectile
    7. /// </summary>
    8.  
    9. public class FireBlaster : MonoBehaviour {
    10.    
    11.     // Variables Start______________________________________
    12.    
    13.     // The Blaster projectile is attached to this in the Inspector
    14.     public GameObject Blaster;
    15.  
    16.     // Quick references
    17.     private Transform MyTransform;
    18.  
    19.     private Transform CameraHeadTransform;
    20.  
    21.     // The position at which the projectile should be instantiated
    22.     private Vector3 LaunchPosition = new Vector3();
    23.  
    24.     // Used to control the rate of fire
    25.     private float FireRate = 0.2f;
    26.  
    27.     private float NextFire = 0;
    28.  
    29.     // Variables End_______________________________________
    30.  
    31.     // Use this for initialization
    32.     void Start ()
    33.     {
    34.         MyTransform = transform;
    35.         CameraHeadTransform = MyTransform.FindChild("CameraHead");
    36.     }
    37.    
    38.     // Update is called once per frame
    39.     void Update ()
    40.     {
    41.         if(Input.GetButton("Fire Weapon")  Time.time > NextFire)
    42.         {
    43.             NextFire = Time.time + FireRate;
    44.             // The launch position of the projectile
    45.             LaunchPosition = CameraHeadTransform.TransformPoint(0, 0, 0.2f)
    46.             // Create the Blaster projectile at the LAunchPosition and tilt it's angle
    47.             // so that it's horizontal using the angle eulerAngles.x + 90
    48.             Instantiate(Blaster,LaunchPosition,Quaternion.Euler(CameraHeadTransform.eulerAngles.x + 90,MyTransform.eulerAngles.y, 0));
    49.         }
    50.     }
    51. }
     
  39. modulo

    modulo

    Joined:
    Sep 10, 2011
    Posts:
    31
  40. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    LOL justintmetal, I can see the error in your code :cool:.

    This line is missing a semi colon at the end LaunchPosition = CameraHeadTransform.TransformPoint(0, 0, 0.2f)

    If you make that correction I believe your script will run just fine. Don't be embarrassed because I'm pretty sure that just about everyone has made this sort of silly mistake. The lesson to be learnt from this is to always look for the most silly errors that could have been possibly made first (like not plugging an appliance into the wall and wondering why it's not working).

    Thanks for posting your code up as it made it easy to debug.
     
  41. justintmetal

    justintmetal

    Joined:
    Mar 6, 2012
    Posts:
    2
    Thanks! the script works perfectly now :) By the way your tutorials are amazing!
     
  42. BloodyRayne89

    BloodyRayne89

    Joined:
    Oct 16, 2011
    Posts:
    31
    Hey GTGD can u make a script for terrain generation? plox D:
     
  43. modulo

    modulo

    Joined:
    Sep 10, 2011
    Posts:
    31
    where is the relation with this tutorial ?
     
  44. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
  45. bajeo

    bajeo

    Joined:
    Dec 5, 2011
    Posts:
    75
    Hey just wanted to post here and say love the series! It is very rare to find a series where you can understand every word so it’s nice not to have to constantly rewind the video.

    I am having a problem which hopefully should be simple to solve. Im not following your tutorials exactly as ive added a master server. My problem occurs when there is more than 1 player:

    Player one joins game -> selects team and spawns correctly. Player 2 joins same server -> Selects team and spawns correctly. The problem is player 1 can see player 2 but player 2 cannot see player 1… (players cannot see 'older' players. I have not changed the spawn script from your design)

    After some research I think it’s a buffering problem?? However in your when you instantiate the players (after they select a team) you simply call Network.Instantiate(…). This doesn’t have an option to buffer the results so not sure what to do next :p Any help/pointers would be greatly appreciated.
     
  46. BloodyRayne89

    BloodyRayne89

    Joined:
    Oct 16, 2011
    Posts:
    31
  47. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I'm sorry bajeo but I've never tried using the Unity Master Server so I can't really say why the network instantiation is not working properly. Network.Instantiate is a buffered RPC (http://unity3d.com/support/documentation/Components/net-NetworkInstantiate.html) so it's odd that it's not working as expected.

    In the past I have made the mistake of writing a plain Instantiate inside a Spawn...TeamPlayer () function, within the SpawnScript, instead of Network.Instantiate and that would bring up a similar situation to what you're describing. Have a look at your SpawnScript closely, though it is more likely that the problem is more complicated than that.

    When you find a fix that gets the script to work for the Master Server please post it up.

     
  48. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I've just released Video 8 Communications!
     
  49. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    Great tutorial;)

    To bad no have JavaScript version:(
     
  50. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I’ve just produced video 33 ahead of time as there have been a fair few questions on how to setup a game over the internet. We have a fair amount of functionality in our game so it isn’t a bad time to try out connecting with friends over the internet.

    In video 33 we cover the following:
    Setup a network using Hamachi and start a server
    Connect to another Hamachi network and connect to the server
    Connecting over LAN

    I’ll also briefly discuss firewall settings for Windows 7.
     
    Last edited: Mar 11, 2012