Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

how to make a multiplayer game like agar.io

Discussion in 'Multiplayer' started by LTE_, May 1, 2016.

  1. LTE_

    LTE_

    Joined:
    May 31, 2013
    Posts:
    19
    Hi, how to make a multiplayer game like agar.io?? I am just wondering about the multiplayer part, what do I need to learn about UNET to achieve something like it. thanks.
     
  2. SirNiklas

    SirNiklas

    Joined:
    Jun 7, 2015
    Posts:
    85
    Your question is formulated way to broad to answer it here. I guess you do not have any advanced networking experience hence you are posting this question? Start reading into tutorials and watch videos, try out what you learned and repeat.

    There are many ways to create a multiplayer experience like its done in Agar.io. The developers used an authoritative client-server environment (source) which already requires all basic features of the UNet high level API.
     
  3. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,138
    Basically what you should do.
    Spawn objects on server using NetworkServer.spawn
    Get movement commands from clients and send them to server,
    Use the NetworkTransform to synch player positions (or make your own synchronization code)
    Detect collision of objects on server and react based on mass.

    What is your question exactly?
     
    Chom1czek likes this.
  4. LTE_

    LTE_

    Joined:
    May 31, 2013
    Posts:
    19
    im curious about the scalability when there r so many players, can unet handle it?
     
  5. srylain

    srylain

    Joined:
    Sep 5, 2013
    Posts:
    159
    That's a question of if you have a server capable of running what you need it to. Each player will use a certain amount of bandwidth, each player will need a certain amount of processing power to read in and send data out and perform collision checks and whatnot, and enough RAM to hold all the player data.
     
  6. LTE_

    LTE_

    Joined:
    May 31, 2013
    Posts:
    19
    so i need to set up my own server that is not included in unet?
     
  7. SirNiklas

    SirNiklas

    Joined:
    Jun 7, 2015
    Posts:
    85
    Hes talking about hardware. First, you need to develop your multiplayer game and try to optimize its performance to the min. Second, you have to host the game either by letting players create lobbies which are set up on their own or rent servers to host dedicated games.

    Call of Duty is a good example for player-based game hosting, DotA 2 is the exact opposite, all games are hosted on central Valve servers. If you let players host by themselves on their own machines, it could well be that their bandwidth is not enough to play this game without lags and other networking problems. On the other side servers hosted by you cost money and are more complicated to set up (in comparison to player-owned lobbies).

    The choice you are going for affects the capability your multiplayer game has.
     
  8. IAMBATMAN

    IAMBATMAN

    Joined:
    Aug 14, 2015
    Posts:
    273
    Can you please tell me how I do this I'm trying to learn UNet by making small browser games, meaning I have no budget for servers and what not. So can I have the player set up a lobby? Any help would be great :)
     
  9. SirNiklas

    SirNiklas

    Joined:
    Jun 7, 2015
    Posts:
    85
    Yes you can, its not even that hard with UNet. You only need to disentangle all the synonyms of the gaming jargon and translate them into more professional vocabular:
    A player is nothing else than a client, a peer who receives commands from a server and sends requests to it. In this case a lobby is nothing else than the server side being hosted by a client peer. So the client both controls commanding and connections of the other clients and is indeed a client by himself.

    This introduces some problems like authoritative cheating by the hosting client and bandwidth limits. A normal videogame player will probably not have the high networking capacity Valve server rooms contain. Because you then have to make compromises and let the connected peers command some gameplay aspects on their own which provides chances for malicious players to cheat, wether being the hoster or not.
     
  10. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,138
    In general putting aside the fact that you want to host your server or use uNet's match making to host games by players, Agar.io is not that much of a network intensive game, each game world/server/instance contains around 30 players and handling this is not a huge issue, specially considering the fact that collision detection is too simple in the game and you don't need special complex, fancy logic to run the game.
     
  11. LTE_

    LTE_

    Joined:
    May 31, 2013
    Posts:
    19
    does unet or unity provide the server?
     
  12. SirNiklas

    SirNiklas

    Joined:
    Jun 7, 2015
    Posts:
    85
    @Ashkan_gc Well its not always ideal to use hosting servers. Client-hosted games have many positive features that can outweight the negative ones like cheating. If the players depend on servers provided by the developer they cant play when there is a maintenance and if the publisher shuts down support for the game the community will be dead. No hosting servers = No multiplayer matches.

    @Exorific Not directly no. Servers to host your games on are expensive but Photon has cloud servers you can rent, of which the prices are pretty okay. There are many hosting services in the internet, Amazon Web Services is among those too. You will have to assume that providing any of these options introduces a problem of money, thats just how it is.
     
  13. IAMBATMAN

    IAMBATMAN

    Joined:
    Aug 14, 2015
    Posts:
    273
    Ok, say I was making a small multiplayer game like agar, and I wanted 10 people to play in the same game, how do I have Client-hosted games without the relay servers or the matchmaker or anything that costs money, please help I really want to learn and practice UNET but I can't really make games that cost any money :(
     
  14. SirNiklas

    SirNiklas

    Joined:
    Jun 7, 2015
    Posts:
    85
    I cannot help you with practical tips as I have never worked with UNet or Photon. But this question you propose here is way to broad again ("How to develop a client-hosted multiplayer game in UNet?").

    Why do other fellow network programmers need to learn this from YouTube videos and long blog posts tutorials? The answer is: Because that is the only way to really learn networking, and its not even real network development. UNet offers a high level API that makes it possible for you to not touch any even remotely complex socket and IP communication source, so just go for it, do it yourself.
     
  15. arshadameen

    arshadameen

    Joined:
    Mar 5, 2018
    Posts:
    8
    In case you need to create a multiplayer game like agar.io then remembers that there are many different ways to do it. You can do it like in Agar.io game. The developers utilized a commanding client-server environment which already needs all simple features of the UNet high level API. Ensure that in the start, you have to make your multiplayer game and try to optimize its performance to the min. Then, just host the game moreover by allowing players make lobbies which are set up on their own or rent servers to host devoted games.

    Call of Duty is a good case for player-based game hosting, DotA 2 is the precise opposite, and all games are hosted on dominant Valve servers. In case you allow players host by themselves on their own machines, it could well be that their bandwidth is not sufficient enough to play this game without lags and other networking issues. Apart from that, the other side servers hosted by you cost money and are more complex to arrange
     
  16. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    216
    This a very late reply BUT a possible solution to this (or at least minimizing the costs) is using Mirror in combination with a relay server with the library Light Reflective Mirror. Its authors change its name sometimes, it used to be called dark reflective mirror so just look around and you will find it.

    Essentially it allows you to direct-connect your players in a host/client setup with NAT punch (note: it introduces issues with public wifis and company wifis tho) or alternatively just a cheap but high latency relay server.