Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Creating online multiplayer.

Discussion in 'Getting Started' started by Severos, Oct 2, 2015.

  1. Severos

    Severos

    Joined:
    Oct 2, 2015
    Posts:
    181
    Hi,
    I'm fresh new to Unity, been around a month since I installed it and started messing around, now I'm planing on creating a FPS multiplayer online game.
    My current view of the project is to split into 2 projects, Server and Client, don't want to have server code in client project to prevent reverse engineering (I know it's still possible in other ways), Server will have no GUI, just start the exe and forget it.
    I want the server to be authoritative, make it aware of the physics and map of the game, so basically clients are just terminals that send inputs, buffer 100ms of game and interpolate state.
    I've read couple tutorials on networking in unity and using authoritative server and such, but they're all old ones that use older Unity versions (before Unity5), so they used Network View.
    Does anyone have guides and tutorials on creating such game with Unity 5, separated projects for server and client along with buffering??

    Thanks in advance.

    P.S: Stuff I've read to help:
    http://forum.unity3d.com/threads/tips-for-server-authoritative-player-movement.199538/
    http://www.paladinstudios.com/2013/07/10/how-to-create-an-online-multiplayer-game-with-unity/
    http://docs.unity3d.com/Manual/UNet.html (didn't understand how to apply most of the stuff here)
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    You might be amused to know how often we hear that.

    Sadly, they all seem to disappear when they find they're in way over their head. On the difficulty scale, if creating recreating Space Invaders is a 1, Mario Bros is a 3, Doom is maybe an 8, and an online FPS client/server game is probably a 30 or so.

    So, if you're planning to accomplish the 30, go ahead and do Space Invaders and Mario Bros first, since they only add 4 to your total effort. And then do Doom, since that's only adding 8 more, but really less than that since much of the effort that goes into that will be directly usable for the 30.

    In other words, quit worrying about the dream game which, if you work hard, you'll be ready to start in in a year or so, and spend that time creating lots of simpler games to level up your skills. You're like a level 1 fighter proposing to go out and slay the level 30 dragon. Smarter to bag some bunnies first and work your way up, no?

    Good luck,
    - Joe
     
  3. Severos

    Severos

    Joined:
    Oct 2, 2015
    Posts:
    181
    I'm fresh to Unity but not fresh to programming or learning new stuff, during the month since I downloaded Unity I was able to get hold of the basic concepts and created a small maze game where you run around a maze and can leave marks on ground and there are some walk through walls, next thing I wanted to add for it is portals.
    I'm not planing to create the next online FPS, just something to mess around at university with friends, I already have read many many articles online on how the server/client should operate along with smoothing and buffering, but all of them were concepts with no demo, let alone some were working in the lower levels such as compressing packets http://gafferongames.com/networked-physics/introduction-to-networked-physics/
    I really appreciate your advice, but I'm still planing on making a server-client game.
    How many points an online multiplayer space invaders would get??
     
    Shujahat-Murtaza likes this.
  4. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    813
    Look for tutorials about UNet, as that's the name of the new networking system in Unity 5. For example, I'm eventually planning to watch the videos in this thread: http://forum.unity3d.com/threads/un...torials-making-a-basic-survival-co-op.325692/

    (incidentally, since you already know how to program then you should checkout my book Unity in Action. It sounds like you already know the basics covered in the first few chapters, but there's plenty of other stuff you probably still want to learn.)
     
    Shujahat-Murtaza and JoeStrout like this.
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    Yep, I certainly don't mean to discourage you, it sounds like you're off to a great start.

    One more suggestion though, if you'll allow it: consider building your FPS game around tanks (or UFOs, or other simple vehicles) rather than heavily armed commandos. That avoids all the problems of character animation and control, letting you focus on the networking, collision detection, and all that other stuff, while still making a very fun game.
     
    Shujahat-Murtaza and jhocking like this.
  6. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    That's why I didn't answer this thread initially. It was clear to me you knew what you were talking about, and I didn't know how to advise you moving forward!

    100.
     
    JoeStrout likes this.
  7. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    Actually, I think I just grokked this question. You mean on my little difficulty scale, where space invaders is a 1, and an online FPS is a 30?

    That's actually a great question, and probably a project worth doing. I'd say it's probably a 10 or so. You have all the difficulties of writing a server, defining your protocol, deploying and testing the coupled apps, dealing with lag and synchronization issues, etc., but the rest of the game is just a bunch of simple sprites.

    How to make multiplayer space invaders interesting is another question... probably one for the Game Design forum!
     
  8. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    D'oh. I meant it as how many points he'd get for doing it, even though I understood your original scale.
     
  9. Severos

    Severos

    Joined:
    Oct 2, 2015
    Posts:
    181
    Oh, I agree with the animation part, I'll probably make the characters as android mascots to avoid animations, it'll be just rotations.

    Do you think I should implement my own networking protocol? like just using a UDP listener and then manually serialize and deserialize them to objects? this approach would give the lowest packet size if implemented correctly, but implementing is the hard part, is it worth it?? or should I just use the built in sync and protocols?? do you happen to have study/search materials that can help?

    And to one of my biggest questions, can I create a separated projects in Unity for Server and Client? I remember reading somewhere that if Server didn't share code with client then it'll be sending the whole prefab on every first sync (or I miss understood that), and how would I make my Server run without GUI? prefer if there's a method to build it as a .dll with some interface to provide info, maybe I'll think of adding a managing system to it.
     
  10. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    The last time I did networking in Unity was before the new UNET stuff, and it was very low-level. That approach certainly still works, but I know the Unity folks have put a lot of effort into making UNET performant and easy to use.

    So I would recommend you start with that, and roll your own implementation only if you find UNET lacking in some fundamental way.

    Since I've never used UNet, I'm not sure what restrictions (if any) it imposes on a separate dedicated server project. When I did it, I wrote the server in C# and compiled it to a command-line app with Xamarin Studio. It shared code with the Unity project, but that's all — which actually made it quite convenient to debug and run them both at once.

    But I'll bow out now and let somebody who actually knows something about UNET jump in... or you could just dig in yourself and see how it goes!
     
    Last edited: Jan 15, 2016
  11. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    UNet is the way to go. UNet is set up so you only use a single build, typically you would use an if (server) type approach. But that's the high level side. UNet also exposes a low level API you can use for greater control.
     
  12. Severos

    Severos

    Joined:
    Oct 2, 2015
    Posts:
    181
    I've read about the if (server) approach and personally didn't like it, using it this way means the server code is included in the client, and I don't want to do this. also when updating some server side stuff that means a new version is created and all clients will have to update version, I know if I didn't change client code then old clients will work, but the update program we're designing will tell user there's a new version.

    The thread is really awesome, thanks for the link. I'm considering your book for now, but probably will buy it after my mid term exams.
     
  13. ninjacreeper47

    ninjacreeper47

    Joined:
    Nov 25, 2015
    Posts:
    1
    Check out a video series called gamer to game developer. Start with S1
     
  14. Nitro00

    Nitro00

    Joined:
    Jan 11, 2018
    Posts:
    18
    A little late to the party but try out Photon, it seems like they've made a better UNet!
     
  15. chrisrobertz123

    chrisrobertz123

    Joined:
    Jan 23, 2020
    Posts:
    1
    I cannot thank you enough for this advice.
    Cheers and good luck ahead mate!