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

New Unity3D Networking eBook and Tutorial with Code Samples

Discussion in 'Multiplayer' started by Quadgnim, Nov 19, 2012.

  1. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    I'm happy to announce I've officially completed my eBook and it's now available for download from my blog.

    http://www.3dmuve.com/3dmblog/?p=201

    In my eBook you will learn about such things as Master Game Servers, Game Servers, TCP/IP vs UDP/IP, Game Matching and Game Lobby Services, Instantiating Network Objects, Animating Networked Objects, Synchronizing a level and objects across clients, Problems with Firewalls and Routers and how to overcome them with NAT Punch Through, and a whole lot more.

    NOTE: If anyone has problems downloading the eBook please be patient. I am working diligently with paypal and my hosting provider to figure out the issue, but I promise you as soon as I receive your email confirmation from paypal on the purchase I will immediately forward the eBook to you in the email supplied with the purchase. Thank you for your support an I apologize for any inconvenience.

    If you aren't able to download just drop me an email at larry.grant@3dmuve.com and I'll send it out. I don't want to clutter up the forum with issues, I'd rather save that for your feedback on the eBook itself. :)

    NOTE 2: I believe the download issues are resolved.

    A few people have indicated a problem unzipping the contents. For anyone who's already received a copy of the eBook, if that happens please try 7zip. I've changed the download to use winzip going forward to hopefully provide more compatibility. Please let me know if you experience any issues.
     
    Last edited: Nov 22, 2012
  2. Yokil

    Yokil

    Joined:
    Sep 9, 2012
    Posts:
    26
    Solved, ty.
     
    Last edited: Nov 20, 2012
  3. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    Yokil,

    I'm sorry for the inconvenience. There was a security setting with PayPal that was preventing download of unverified PayPal users. I think I have the issue resolved, but please let me know your personal email address and I'll send you a direct copy of the eBook. If you can just forward me the actual PayPal email receipt then I can correctly update the system and send you a copy back. I really appreciate your patience and I believe the problem has been resolved.

    You might also try returning to the website and trying to download it again from the purchase history tab across the top. I just looked and the system indicates all transactions completed successfully.
     
  4. Milad-Fathi

    Milad-Fathi

    Joined:
    Nov 9, 2012
    Posts:
    32
    hello, i am Iranian. and PayPal is not available in Iran. How can I purchase the book?
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    Hi,
    Same error here "You do not have permission to download this file"

    Purchase confirmation page says,
    "Thank you for your purchase!" and its has the download link, but cannot download..

    Maybe it is because paypal email was different from the site registration email?
     
  6. Yokil

    Yokil

    Joined:
    Sep 9, 2012
    Posts:
    26
    Solved, ty.
     
    Last edited: Nov 21, 2012
  7. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    Sorry to everyone for the inconvenience with downloads. I think I've sent everyone a direct copy of the eBook at this point. I plan on updating the paypal plugin I'm using on my Wordpress site, but until I do, just continue to email me directly and I'll be sure to send the eBook asap. Thanks for your patience in this matter and I appreciate all the support.

    Do me a favor and LIKE my fan page on facebook, I'm trying to build up followers: http://www.facebook.com/3dmuve
     
  8. augasur

    augasur

    Joined:
    Mar 4, 2012
    Posts:
    133
    Hi,
    Sorry for strange question, but what networking does this use: Unity standart networking, photon, or smartfox? And another question :does this supports unity mobile (android, IOS)


    Thanks.

    Augustas.
     
    Last edited: Nov 20, 2012
  9. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    This is not a strange question at all, it's the type of questions I'd like to see on the thread. This is 100% Unity Standard Networking and has been tested with both versions 3.x and 4. As far as I know it would work on Android, but I've only tested it on PC and MAC. If there is interest in Photon or Smartfox let me know and maybe it'll be a future eBook.

    Larry
     
  10. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    Thanks got the file!

    ps. For some reason winrar was unable to open the project zip file, but 7zip works fine.
     
  11. augasur

    augasur

    Joined:
    Mar 4, 2012
    Posts:
    133
    Thanks, I have bought it :)
     
  12. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    augasur, any problems with the download, or did it work ok for you? I made a configuration change which I'm hoping worked?
     
  13. augasur

    augasur

    Joined:
    Mar 4, 2012
    Posts:
    133
    Hi,

    Yes everything worked, I got the file. I have read a bit the PDF, but I haven't time to test the packages, I am looking forward to test it, but now I have another project to do, so as soon as I will test it, I will post the results. :)
     
  14. Naxum

    Naxum

    Joined:
    Nov 21, 2012
    Posts:
    4
    Howdy, I'm interested in buying the eBook, but I'm extremely uncomfortable with entering my PayPal information directly onto your site. If there was a way for it to forward the information to paypal, I would be willing to buy it. Seems a little sketchy to me honestly, just having the icon above a couple input fields.
     
  15. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    You aren't entering your paypal information on my site. You are entering a name ane email address for my contact list, then it forwards you to paypal's site to properly login for payment.
     
  16. Milad-Fathi

    Milad-Fathi

    Joined:
    Nov 9, 2012
    Posts:
    32
    Hi All.
    I got this ebook . and just can say it's awesome. very cool. I Love this Book and I love it's author. Unfortunately my English is very bad and I cant show how I feel. this book is a very good point to start learning about unity networking for beginners. and also a good thing to improve networking abilities for Advenced.
    Thanks Larry
     
  17. foxter888

    foxter888

    Joined:
    May 3, 2010
    Posts:
    530
    how come you are not selling the book on the asset store? then not many people would have to worry about paypal
     
  18. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    I have submitted the eBook to the asset store but I'm still waiting their acceptance. Also, the lowest price you can set something in the asset store is $2, not .99 cents. Hopefully in a few days it'll be your choice where to buy and what to buy. I'm not trying to make money on the eBook, not for .99 cents, but any little bit helps cover the costs for the website itself and other supplementary costs.
     
  19. Jaybones

    Jaybones

    Joined:
    Jul 14, 2012
    Posts:
    13
    Just pickup your E-book.
    And yes if you make one for Photon i'll be very interested.
    jay
     
  20. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    I do discuss authoratative servers a little bit, but I mostly focus on what I coined the "Hybrid Server." The authoritative server performs all the logic for all networking related tasks. This is ok, but it relies on a much more powerful server and if done purely would also slow down the responsiveness.

    Instead I discuss a variation where each client owns it's own decisions for the objects it owns. For example if player A shoots player B, both clients will detect the collision, and both clients could play a collision effect, but only player B's client would perform the damage processing as it was player B getting hit. Player A who performed the shooting doesn't detect the hit then tell B to apply damage, instead B only applies damage when it detects something hit it.

    In Appendix A when the spear is thrown it performs a little more authoritative processing in that the client throwing the spear then asks the Game Server to actually perform the throw, so the GS then owns the spear.

    Also the GS will own all non player objects such as power ups, etc...

    Hope that helps.
     
  21. miroslaw

    miroslaw

    Joined:
    Nov 15, 2012
    Posts:
    70
    Thanks, I had bought your ebook :).
     
  22. miroslaw

    miroslaw

    Joined:
    Nov 15, 2012
    Posts:
    70
    Excellent tutorial by the way! I'd definitely recommend this to any beginner as it covers the basics on how to start your networking game. I've been able to build off of what I learned in this tutorial easily. I've posted quite a bit on this forum and all my questions were answered and cleared up in this tutorial also. Thanks again!
     
  23. Mikie-J

    Mikie-J

    Joined:
    Aug 28, 2012
    Posts:
    2
    have been doing my own networking bits trying to get to grips with it, wish id jumped straight to your book -nice one - well written too. def worth it for less than 1 pound :)
     
  24. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    Just finished the tutorial, works fine!

    Some ideas:
    - More images (maybe couple images for those network models also, 'here is master server, here are the clients', sendall sends data from ... to ...)
    - Some "info boxes" on the sides like in those 'for dummies' books: "TIP. networkview blahblah automatic blah", "Warning: this asdfasdf creates asdfasdf"
    - Somehow highlight things to do?
    - Common errors/problems solutions page (related to unity network games)?
    - Part 2.. continue from here.. (raycast guns, show ping, chat, teams, ..etc)
     
  25. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
  26. ProtoJazz

    ProtoJazz

    Joined:
    Nov 27, 2012
    Posts:
    19
    Just bought the book, it looks really good. And for $0.99 its more then worth it
     
  27. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
  28. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    Can you describe or even have the code for the Appendix C in the ebook ?
     
  29. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    Thank you for your support, I hope you enjoy the eBook. I'm sorry but there is no code for Appendix C, this was just a list of ideas I thought of as I was writing the eBook, and decided it would be good to let the reader do it themselves instead of providing every specific detail. With programming there is no one way or right way to do anything, so I thought it a fun project for the reader and not something I would provide. If you're able to get through the eBook and understand everything you shouldn't have a problem with the few additional exercises in Appendix C. If you get stuck on any specific topics please don't hesitate to ask for help and I'll do my best to guide you in the right direction.
     
  30. enter360

    enter360

    Joined:
    Nov 27, 2012
    Posts:
    2
    I'm also interested in anything you do with Photon. I'll pre-order if it helps move things along.
     
  31. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    For Appendix C, can you give me some direction on how to create dynamic obstacles that can be damaged or even can attack to player.
     
  32. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    There is a very serious problem for the multiplay network game. It happen in your example scene or even the unity3d network example.

    When the player with camera followed and the remote player move at the same time, In the player view, the remote player will get jitter.
     
  33. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    hmm, I haven't experienced this myself, but I'll go back and see if I can somehow reproduce it. If I had to guess I'd suspect one of two things you might be experiencing.

    1. if you don't properly disable the controller on the remote avatar, then when you move both controllers they'll both be trying to move the remote avatar at the same time, so that could result in a jitter (or worse). To test, just move a single player while seeing the remote player on the screen and see if the remote player also moves, even though you are just attempting to move the one. This is part of the PlayerSpawnInit:

    PlayerControl pc = (PlayerControl)parent.GetComponent("PlayerControl");
    pc.enabled = false;

    2. The other possibility is that its due to actual lag. If you are running two computers, are they on the same network or connecting over something very slow? Hopefully not a dial up modem or even slow DSL?

    As for the question on creating dynamic obstacles and damage, that's for the most part covered in appendix A. The throwing of a spear is dynamically creating a new spear each time, and as for the damage, I left placeholders in the code where you can apply the damage on collision. The trick is to only apply the damage once so you need to figure out where to do that. Some designs use an Authoritative Game Server design, where the collision has to be detected on the game server in order for any damage to be applied to a game object. Another approach is the one I focus on in the eBook which is what I've coined the Hybrid Model. In this model the collision occurs on each client independently, but only the client who owns the networkView.isMine for the player that was in the collision will apply damage. All the other clients just play the animation and clean up as necessary, but just the one actually updates damage, then checks for death. If dead then send a network update to all clients to play a death animation then remove the player.

    Hope that helps.
     
  34. Darjamfar

    Darjamfar

    Joined:
    Jun 4, 2012
    Posts:
    63
    I'm just getting into developing networking for my game. I want my networking game to be turn based, one player does something and everyone can see it, then the next player does something etc and keeping scores. Does your guide cover that ?
     
  35. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    To be honest it focuses more on a live action, twitch style networking. However, you'd probably gain a lot from this eBook anyway, around the overall teachings on networking concepts. Furthermore, the turn based networking is one of the easier to implement. I think you'd gain all the necessary skills to get it working on your own, but its entirely up to you.

    Best of luck.
     
  36. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    1. I am using your code without any modification. 2. I am in Local WiFi network. The strange is that If the main camera is fixed, both players move smoothly.
     
  37. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    yuewahchan, I've tried to reproduce what you're experiencing, but I'm unable to see any jitter other than the normal lag which over a LAN is so minimal its hardly comprehensible for me. Could it be that you're used to a moving object being animated, with legs moving and hands swinging or a hud bopping up and down and this sample uses very simplistic graphics so it's throwing you off? If your jitter is bad the only other thing I can think of is either you're on a slow computer not really good for running Unity, or maybe the directx drivers are out of date, or something like that? I'm running it on two computers, both over wifi, one a MAC and one windows7 running virtualized on a second Mac, and everything is great. I'm running with one player a few steps in front of the other player and both are moving forward. I'm not seeing any issues. When I have time I'll cut a video and post it on youtube. Then you can compare it to what you're seeing. Sorry I don't have any other ideas on this one.
     
  38. Darjamfar

    Darjamfar

    Joined:
    Jun 4, 2012
    Posts:
    63
    Hey i bought your guide, for £1.28 it looks a steal !

    Having played around with the Demo in the zip file, I feel it needs to keep score of how many hits each player has taken. That would help me enormously.
     
    Last edited: Dec 10, 2012
  39. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    Thank you for the support. You're right, keeping score and showing it on the screen would be a good thing. In Appendix C I talk about just that. However, I've not included it in the eBook as I didn't want to over complicate the examples. I wanted to keep it focused on networking specifically. If you go through the ebook there are sections where I left placeholders to provide a scoring/hit/damage system. Specifically its in the oncollisionenter methods.

    Good Luck.
     
  40. Darjamfar

    Darjamfar

    Joined:
    Jun 4, 2012
    Posts:
    63
    Thanks for the pointer, but don't worry about the added complexity - i see it as a fundamental part of what your trying to teach.
     
  41. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Even though i am using Photon my self, i will buy this soon! Just because i love people who put in so much effort to help others out without charging almost anything!

    Cheers! (And can see it is on the Asset Store now!)
     
  42. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    Thanks BFGames, I really appreciate the support. Yes it is on the asset store, just search 3DMUVE, or 3DMUVE under Networking. This way people can either get it directly from the asset store or from my Blog, whichever is more convenient for them.
     
  43. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    In my case,
    1. the frame rate is really high
    2. the network ping is low ( less than 1 ms).
    3. no animation ( use your example scene )

    The most important point is that If the main camera is static, all network player move smoothly, jitter only happen on remote player if camera is attached to the local player.

    Also, I tested on iPhone4 as client, the jitter is even worse. So hardware or network performance may be a factor.

    Finally, I replace all rigidbody to CharacterController, it somehow eliminate the problem.
     
  44. Darjamfar

    Darjamfar

    Joined:
    Jun 4, 2012
    Posts:
    63
    Just working through your eBook. One thing that doesn't work for me is copy paste of the code (using Mac and preview). It misses off code so i have to go to the finished project and copy/paste that. I probably should type it in and learn more.

    I followed the StarTrooper tutorial and your method is different to that, so it's taking some getting used to ! As i want to do a 3d turn based game, is your framework suitable for this kind of game ? It seems using your method i can talk to clients and control them better than i could with the StarTrooper methods. Is this right ?

    Do you have any tips on how i might approach this type of networked game ?

    Thanks!
     
  45. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    A few things. First don't try and cut/paste. The Footers on each page mess up the paste. Also I cheated on the formatting so it looked right in the PDF. Instead I've included all the code as a Unity Package, so just import the package then cut and paste all you want from it.

    As for a turn based game you usually want an AUTHORITATIVE Game Server (AGS) to manage each turn. The AGS can be the same client who starts the game. Then in the update routine of your user input class you'd check to see if its your turn or not, and ignore any move attempt if its not your turn. Then when it is your turn you make the move, hit submit, and send the move to the AGS via an RPC. The AGS will process the request and if acceptable send an RPC update to all players instructing what the move was and who's turn it is. This process would repeat.The networkView State Syncronization and Observed should be off/none respectively as I think everything will be an RPC, although I don't know you're game details well enough so I could be wrong.

    Best of luck
     
  46. Rabbit

    Rabbit

    Joined:
    Dec 30, 2012
    Posts:
    8
    Awesome book dude! Read it on my phone in a couple hours. Best $2 I've spent.
    Very well written/constructed, shows you what you need to know but doesn't over complicate it
    even whilst explaining the very fundamentals of networking.

    Please write more ebooks I will buy anything you write.

    Thanks
     
  47. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    1. I click "Start Server" on server
    2. I click the host on client
    3. I click "disconnect" on server side, it return to MasterGameServerLobby scene ( 3 MasterServerMenu GameObjects exist )
    4. I click "Start Server" on server again
    5. I click the host on client -> it throw many error "View ID SceneID: 1 Level Prefix: 1 not found during lookup. Strange behaviour may occur ......
     
  48. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    It's just that the network isn't getting reset. Off the top of my head I would suggest trying, or something similar to below. Realize, the tutorial in the eBook isn't intended to be a production ready framework, but was intended to provide just enough of the basics to use for training without over complicating things. I hope this helps.

    void OnDisconnectedFromServer()
    {
    // When we drop the server then we need to reset the network and return to the main menu to start over
    Network.Disconnect(); // Tell all the other clients you're disconnecting
    }

    Larry
     
  49. dsfsdfsdfsdf

    dsfsdfsdfsdf

    Joined:
    Feb 13, 2013
    Posts:
    1
    I have bought your ebook;-)

    but I know javascript, c# hardly for me...
     
  50. Quadgnim

    Quadgnim

    Joined:
    Sep 10, 2012
    Posts:
    132
    Thank you for your support. It's actually very easy IMHO to convert between the two, and I provide a section that discuss some of the main differences to hopefully make it easier. The core networking concepts are still the same, which is the main purpose for the book. There was another reader who said he was going to create a javascript version of the code. I don't know if he's still following this thread but if so maybe he could share?