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
    My setup is non-authoritative because mostly the player takes charge of their own behavior and then tells the server and other players what happened. The multiplayer aspect of my prototype will work via LAN, port forwarding, or Hamachi. There's no list of servers like we'd see in most games and that's where the Unity Master Server comes in, which is something I'll be studying so that I can implement it for Series 2. I'll also look into having a lobby so we can select different maps and that's for the future of course.
     
  2. Minifig3D

    Minifig3D

    Joined:
    Jun 5, 2012
    Posts:
    4
    Woo! I am now caught up with the videos to date. I am really looking forward to adding those pickups and later some rockets. ;)
    I skipped the videos about adding the blocks though. I am more interested in making an action shooter, like halo or unreal tournament.

    For Series 2, I would suggest some basic things like the ability to load different maps depending on which one the server is currently running, different game modes like capture the flag, and weapon pickups where the player does not always have every weapon in the game but rather has to find the rocket launcher somewhere on the map.
     
  3. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Video 20 Recharge Pickups is now out! In this video you'll see how to setup pickups that are network enabled.

    Thanks for the suggestions for Series 2. I'll be listing down all the topics that viewers would like to learn and I'll plan the content for future series accordingly. This will also define what I'll be studying into the future.
     
    Last edited: Jun 17, 2012
  4. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Video 21 Fall Damage is now out! You'll learn the logic of how to recognize what a fall is and then apply appropriate damage.
     
  5. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Video 22 Player Stats is now out! In this video we implement player stats that can be customized before spawning into the game.
     
  6. technotdc

    technotdc

    Joined:
    Oct 21, 2011
    Posts:
    60
    amazing video 23 ¡¡
     
  7. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks! I'm aiming to get the next video Hurt Effect out by this Sunday. In that video I'll show you a simple way of making the screen become red for a few seconds (using a simple texture) to alert the player that they've been hit by something.

    Oh and wait till you see video 26 where I'll show you how rockets and area of effect works across the network!
     
  8. technotdc

    technotdc

    Joined:
    Oct 21, 2011
    Posts:
    60
    I'm waiting for that video ....

    I have a question too, a problem that I found ....

    I created a large map (buildings, houses) .... I have put into the project .... (I've exported as. Fbx) ...
    The problem:
    I've put a mesh collider at the map ... but I can not make them work collisions between players and the map ......


    Is it possible to do this or not??
     
  9. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436

    It should definitely be possible. The plane that we've been using in the videos also has a mesh collider.

    Maybe this Unity Answers page might help you
     
  10. technotdc

    technotdc

    Joined:
    Oct 21, 2011
    Posts:
    60
    ok........now it works fine ......... (was a problem importing the .fbx file mesh)
     
  11. technotdc

    technotdc

    Joined:
    Oct 21, 2011
    Posts:
    60
    Hi ....
    First, thanks for hurt video

    and......again a question

    ¿ how can i change the screen position of this 3 elements???
    (1 is crosshair .....is not in the middle)





    (sorry my english)
    Regards
     
    Last edited: Jul 23, 2012
  12. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    1. The Crosshair script controls the position of the crosshair.

    2. The StatDisplay script controls the position of the health and energy window.

    3. The ChangeWeapon script controls the position of the selected weapon window.
     
  13. technotdc

    technotdc

    Joined:
    Oct 21, 2011
    Posts:
    60

    Thanks one more time GTGD ¡¡¡

    can you help me to create a simple shoot sound in Fireblaster script???????

    I'm trying with public AudioClip shootsound; ( and ) audio.PlayOneShot(shootsound);


    but does not work
    (well ,I cant do)

    any help ?????


    Regards
     
  14. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    If it's a sound that all players need to hear then you'll need to create a new RPC in the FireBlaster script that gets executed in the Update function when the player presses their fire weapon button. The RPC would execute the audio.PlayOneShot(shootsound) code that you have above. Maybe audio.Play() will work better? This Unity Answers page looks very helpful.
     
  15. dannykario

    dannykario

    Joined:
    Jul 28, 2012
    Posts:
    10
    Hi,

    first - your videos are great, thanks !

    short q - is there any tutorial/instructions to integrate a model + animation (for example from http://www.youtube.com/watch?v=F4zujkA0Ufo which is free
    or similar) for the player ? that is - what are the main modifications I should do to keep the multi player FPS view, but let the player see the other players as a model (with the relevant animations) and not just the "default" shape ?

    Thanks In advance for the help, Best
    danny
     
  16. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I haven't replaced the capsule player with an animated player yet but my guess is that I would place the player model into my Graphics GameObject that's sitting inside my player prefab. I'd remove the capsule mesh renderer, I'd place an animation component, assign each of the player animations to that component, and then attach a new script that I'd need to write for executing the player animations.

    When executing each animation I'd need to make sure that my animation state (probably would be using booleans to define what state the player is in; i.e. jumping, running, etc.) is synced across the network using RPCs or using OnSerializeNetworkView like this suggestion on Unity Answers. Personally I'd probably try and go with the RPC route as I'm more used to that.

    Our MovementUpdate script would remain as it is as we'd still need to keep the player's position and rotation updated across the network. The above is only about syncing the player's animation.

    If we were really clever though it might be possible to not have to sync the player's animation across the network and instead play an animation that is determined from the player's position relative to their last position or maybe their current velocity (this value would have to be updated by an RPC). I recently saw a video by OneManArmy3D where he has the player animating nicely across the network. In his comment to me he mentioned that he is only keeping the player position and rotation updated across the network.

    I'd also suggest checking out Unity's own Bootcamp demo and AngryBots demos to see how they've configured they're player characters.
     
  17. CrazeDevelopment

    CrazeDevelopment

    Joined:
    Nov 26, 2010
    Posts:
    22
    Just wanted to let you know that you've done a fantastic job with these tutorials.

    I am curious to what your programming background is and what projects you are currently working on.

    (If that isn't too presumptuous that is)
     
  18. Venged

    Venged

    Joined:
    Oct 24, 2010
    Posts:
    500
    Thanks for making this series. I just discovered it today and look forward to finishing all of the lessons in the series.

    Nice job!
     
  19. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks for the comments from both of you and as to my programming background, I started learning about programming by learning to write code in Visual Basic 5.0 and I think that was about a decade ago. I choose to learn programming as a hobby from time to time though I do occasionally use my knowledge of programming in my occupation, which is mechanical engineering and project management in the rail industry. So I'm not a programmer by profession.

    My main hobby project is this series 1 and I chose to learn scripting with Unity because it's the first game development technology that I've come across that a single person can actually learn and build something meaningful (that's subjective of course :)) without becoming overwhelmed. I chose to make this project an FPS though the truth is I'm not a fan of first person shooters, for me they are just easier to understand and explain than most other game genres. My intention with this series is to show the average gamer that anyone can develop a concept if they really put their mind and effort to it, as I personally dislike seeing people using up the majority of their free time by playing games and not learning something, or not achieving something that has a lasting benefit for themselves or others.

    Well I think that sort of answers your questions CrazeDevelopment.
     
  20. Ramsar

    Ramsar

    Joined:
    Jul 22, 2012
    Posts:
    34
    Tried to access you webpage, but I am unable to open it. Is it down for some reason?
     
  21. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I've just checked and it looks like it's up and running. Maybe it was temporarily down, anyway let me know if it still isn't accessible.
     
  22. Ramsar

    Ramsar

    Joined:
    Jul 22, 2012
    Posts:
    34
    It works now, must have been a temporary thing. Anyways, thanks for the tutorials, they're a great way of learning Unity (in combo with C#). Especially as having made an multiplayer FPS is definitely something to brag about ;)
     
  23. fano_linux

    fano_linux

    Joined:
    Jan 1, 2012
    Posts:
    909
    Wow let me check it when i get home...Thanks for sharing
     
  24. Ramsar

    Ramsar

    Joined:
    Jul 22, 2012
    Posts:
    34
    I've completed the first four videos and I must say so far this is a great tutorial if you want to learn more about how to create multiplayer systems. Highly recommended!

    However, I do have one question. When typing in the player or server name the player or server window flickers at every keypress. The same behaviour is there when 'backspacing' away a name. Is there a way to avoid this?
     
  25. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    The window shouldn't flicker. That's an indication that something is wrong. I'm not sure what might be wrong for you but check that the window size is defined correctly in your script and check that run in background is enabled.
     
  26. Danila24ru

    Danila24ru

    Joined:
    Sep 21, 2012
    Posts:
    17
    GTGD, can you help me..
    I did multiplayer with you tutorial and now i have a problem:
    why when i play with +2 players i can control of character my friend...
    If he not press any buttons, i playing and him character too play, for example i press "A" and him character too press "A" and going with me in left (mirror)..
    But if he press any buttons (w,a,s,d) him character coming back in him position..
    I think that this problem in character controller, playerRed have same controller of playerBlue..

    How i can fix it?
    (sorry for my english)
     
  27. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    My guess is that one your functions is not named properly or you're missing a bit of code. The spelling and case of inbuilt Unity functions such as OnPlayerConnected is essential otherwise it just won't work. My suggestion to you would be to make a backup of your scripts and then start copying mine in one at a time and then testing the game. This way you can try and identify which script is not working like it should. My initial guess would be that it is either the MultiplayerScript or the SpawnScript that has a problem in it. Look for errors in the Unity editor as well.

    Also have a look at the FPSInputController script and make sure it has the if(networkView.isMine == true) line in the Awake function as the purpose of that is to prevent you from being able to control other players.
     
    Last edited: Sep 21, 2012
  28. Ramsar

    Ramsar

    Joined:
    Jul 22, 2012
    Posts:
    34
    When you are in MonoDevelop you often skip to the next line when typing in the parameters for a function (if there are many of them), which then places the cursor on the next line exactly below the opening bracket of the function. With which keyboard shortcut or key do you do that?
     
  29. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I don't use any shortcut. I just press Enter and sometimes Backspace if need be.
     
  30. Ramsar

    Ramsar

    Joined:
    Jul 22, 2012
    Posts:
    34
    I see... 'cause when I press Enter the cursor always jumps to a wrong indent.
     
  31. Danila24ru

    Danila24ru

    Joined:
    Sep 21, 2012
    Posts:
    17
    Thank you :) Its was this problem..

    Can you in future make tutorials about Animation character FPS, really its big problem for me, and i cant find any good tutorial now..
     
  32. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I might one day, but not anytime in the near future (so probably not till after 2013 or 2014).
     
  33. Ramsar

    Ramsar

    Joined:
    Jul 22, 2012
    Posts:
    34
    Do you intend to immediately start with a second series of tutorials when you complete the first one? If so, can you already share what they'll be about? :)
     
  34. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Series 1 took me a year and a half working away in my free time so I'm guessing that there won't be a Series 2 for a long time yet :). When I get to video 34 I'll probably say a bit more.
     
  35. Latedi

    Latedi

    Joined:
    Aug 25, 2012
    Posts:
    12
    I'm very grateful for Series 1 it really got me into programming for Unity. I was doing some of the official tutorials before but they felt like they were on a much higher level. As I want to eventually become an indie developer I really need to learn this (already got most of the graphics part covered ;) ). But yeah without this I'd still be at square one but now I can do basic programming and solve problems on my own.

    Currently I've used the information to start creating an arena based 1v1 game where the player's control wizards that can fly around and shoot spells etc. Although I haven't set the game design in stone or created graphics yet the programming seems to be working more or less. Much of what I've done is based off of scripts from the prototype here or possibly combined with some information found with google. Here are 2 pictures of progress if you're interested, sorry about the big resolution. Was going to post them as imbedded images but it would kind of clutter the forums a lot.

    Fireballs
    http://i.imgur.com/DA2op.jpg

    Lightning
    http://i.imgur.com/XbNz1.jpg

    One again thanks for the tutorials it really helps and goodluck with your next project!
     
  36. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks for sharing! The big resolution is not a problem at all and it's really neat that you've got the code working. Since its 1v1 arena I could almost imagine a real time action packed mage vs mage game where the players do their best to out smart and out maneuver each other. It'll be nice to see how you progress as time goes on.
     
  37. Latedi

    Latedi

    Joined:
    Aug 25, 2012
    Posts:
    12
    I already have a blog but I guess I'll add my posts to the WIP forums here as well so you can check out the progress if you want to :)
     
  38. Ramsar

    Ramsar

    Joined:
    Jul 22, 2012
    Posts:
    34
    I've just completed video 7 in which part of the HUD is programmed. To adjust the GUI (box positions,...) I change a bit of GUI code, build the game and then check what the changes look like in the game. However, this is very time consuming since I have to wait for the game to build, start and run the game before I can see the changes. Is there a way to develop the GUI more efficiently?
     
  39. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks, I'll keep track of your progress every now and then. Btw, I'd recommend that you include the link to your blog in your signature.
     
  40. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I think there are third party plugins to make things easier but at the moment I don't know a better way of positioning GUI items. I know what you mean, it would be nice if GUI items could be positioned without code like in MS Visual Basic.
     
  41. Ramsar

    Ramsar

    Joined:
    Jul 22, 2012
    Posts:
    34
    I've dropped the question in the GUI forums and got this as an answer. I just tried it out and it works like a charm.

     
  42. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks! That's simple and brilliant. I never even thought of doing that and it certainly makes sense.
     
  43. William-Cain

    William-Cain

    Joined:
    Oct 19, 2012
    Posts:
    8
    Yes there is a trick that I use to help with this. I was in the same position and it took lots of time. Make the box or other gui variables adjustable and then change them in game to set as you like then just copy the values to the code.

    Ex.

    original

    if (GUI.Button(Rect(10,10,50,50),btnTexture))
    Debug.Log("Clicked the button with an image");

    change to

    var x : int;
    var y: int;
    var xSize : int;
    var ySize : int;

    if (GUI.Button(Rect(x,y,xSize ,ySize ),btnTexture))
    {
    Debug.Log("Clicked the button with an image");
    }

    Then when you run the game adjust the variables in the inspector to the position that you like and then just copy down the int values you have into the code. I hope this helps.
     
  44. William-Cain

    William-Cain

    Joined:
    Oct 19, 2012
    Posts:
    8
    GTGD I wanted to also add my thanks to you for this tutorial series. It is a fantastic series that has answered basically every networking question I had. With these foundations I think I can make about anything now. Great job!
     
  45. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thank you for the feedback! If it's ok with you could I use your comment for my Steam Greenlight submission?
     
  46. Nomad5oul

    Nomad5oul

    Joined:
    Aug 18, 2012
    Posts:
    24
    @GTGD

    Thanks for the tutorials. How much work is required to get networking into a game?

    I have a FPS which I'm already working on and I just want to get some networking in there for deathmatch.

    Thanks
     
  47. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Once you understand how networking behaves in Unity and have a feel for the Unity API with respect to networking I think you'll actually spend a fair amount of time planning how to integrate networking into your game. Yes, it is fair bit of work to convert a single player game into multiplayer because you have to think differently, but it isn't overly difficult. The key is to understand how networking behaves in Unity. That took a couple of months to click for me (there weren't any good video tutorials available then for multiplayer) and from then it's become fairly straight forward for me to plan out how to implement a feature that needs to be synchronized across the network.
     
  48. Msxes

    Msxes

    Joined:
    Nov 11, 2012
    Posts:
    1
    Hey!
    I'm on the six video ,and have little trouble here in hit detection system.
    I'm do everything like You said in tutorial ,but the detection isn't work for me.
    After building a game and shoot to the player ,energy is still 100.
    There is no any error ,i really dont know what to do :(
    Im be very greatful for help.
    Regards.
     
  49. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Sounds like to me that your players are not getting added to the PlayerList because that is the backbone for hit detection to work. I'd recommend that you check the case you've given to inbuilt Unity functions like OnPlayerConnected and OnConnectedToServer because it's a common mistake for learners to type it as onPlayerConnected or misspell it.

    Here are the inbuilt Unity network functions http://docs.unity3d.com/Documentation/ScriptReference/Network.html
     
  50. GlitchBait

    GlitchBait

    Joined:
    Sep 20, 2012
    Posts:
    8
    I can't thank you enough for not only making this series, but for also maintaining this thread. I look forward to your future videos.