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

WebGL Game with Client Server Communication

Discussion in 'Multiplayer' started by yachting, Apr 29, 2019.

  1. yachting

    yachting

    Joined:
    Nov 4, 2018
    Posts:
    1
    Hello,

    I'm working on a game where people have to find the right picture (kinda like memorie). I want to save the time people needed for it on a server and save the best 5 people to have a leaderscore. The game will be exported as WebGL and put on a website.
    I was googling around, but I really don't know what to use for backend. I thought it would be a good idea to use NodeJS and setup a Database, but I don't have any NodeJS experience. I had some experiences with Python and Flask. Now I read something about UNET.
    Is there a way todo this with NodeJS, Flask, UNET or maybe something better I don't see yet? and are there any tutorials you could recommend?

    Thanks and have a great day :)
     
  2. LukeDawn

    LukeDawn

    Joined:
    Nov 10, 2016
    Posts:
    403
    SmartFox or Mirror (Community build of uNet)?
     
  3. g_a_p

    g_a_p

    Joined:
    Mar 16, 2015
    Posts:
    279
    It is not clear if this will be a multiplayer game or not. In other words, are the players competing with each other in finding the picture on a common board/area/etc, taking turns to select pictures?
    If yes, then SmartFoxServer could be useful, as pointed out by LukeDawn. Here you can find a number of examples of increasing difficulty, including a turn based game that could be a perfect starting point: http://docs2x.smartfoxserver.com/ExamplesUnity/tris
    If instead players are on their own and you just need to save the time it took them to find the right picture, then a multiplayer server backend seems quite an overkill. A simple php page and a database will be more than enough (but you still have to take into account the overall security... you don't want anybody to post their score directly without even playing the game).
     
  4. Katori

    Katori

    Joined:
    Nov 30, 2009
    Posts:
    60
    If you are going to have any physics in your game then the best solution available today is to use Mirror, perhaps with some physics syncing Asset like SmoothSync or NetworkSyncTransform or writing your own physics syncing system. That way you can have an authoritative physics host/simulator running on a dedicated server. If your game is a board game, card game or any other game without physics then you should write your game with any HTTP framework of your choosing, node.js, .NET Core, perhaps Python if you are comfortable with that.

    Of course, you can also use Mirror for board and card games. Many of our users use Mirror for board and card games and other games without physics, because Mirror enables you to focus on gameplay programming and not writing reams of serialization code (though you can do that if you want).

    On the WebGL front, I just release RocketSockets, a "supertransport" for Mirror that allows you to run multiple WebSockets servers from a single host, cutting down overhead and moving all the networking totally outside of Unity, while retaining 100% compatibility with Mirror APIs. It works great with and was especially designed for and battle-tested with WebGL games. If you're interested, PM me and I can send you a discount code. Of course, Mirror includes a fully functioning WebSockets client and server that runs the networking "traditionally" (inside of Unity), so you can get started with that and swap out the transport at any time.

    Feel free to contact us in the Mirror Discord if you have any questions.
     
    russisunni and Twyker like this.