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. Dismiss Notice

Question Networking library for API built with PHP?

Discussion in 'Multiplayer' started by Sachem1000, Jun 6, 2023.

  1. Sachem1000

    Sachem1000

    Joined:
    Mar 17, 2023
    Posts:
    7
    Hello

    Some background:
    I am working on a 2D multiplayer MMORPG game (top-down graphics). Because I am a web developer with 15 years of experience (and I built similar game in the past for web) I started building this new game with Angular/Ionic/Capacitor (front-end stack that allow to compile/release for the Web, Android and iOS) and PHP/Laravel + NodeJS for the back-end API.
    The project is in quite advanced stage already - amongst other things I have the networking part almost ready, but more about it in a sec.

    Now comes the tricky part ;)
    Few months now I found out about Unity and fell in love with it!
    So my idea now is to rebuild the front-end with Unity to make the game more appealing.
    At the same time I do not want to throw all my hard work away so I would love to keep the API as I have it and communicate with it from Unity.

    To give you some details about how I plan to communicate with the back-end (MySQL + Redis):
    1) HTTP requests for things like:
    - loading location data with GET, when player visits them
    - sending a POST when user crafts an item or buys something from the shop
    etc.
    2) WebSocket communication (via NodeJS) only for:
    - sending move requests
    - syncing/displaying other players on the map, as they move

    The game will be a crafting / mining / trading focused so I do not care if the players will not see themselves super-accurately on the map as they move, it's enough for me if they see other players around.

    The way it works in my Angular implementation is:
    - user clicks a location in the map
    - client calculates the path to get there (player location in the map is grid-based so while they are animated pixel by pixel, the location on the server is saved as world coords (X,Y))
    - calculated path is sent to the server so other players are notified of the movement
    - the server updates the players position every X ms (when s/he is supposed to get to the next tile) - this is to prevent cheating, but that is irrelevant here, I guess
    - if a player clicks another location before reaching current destination, new path is calculated from the point s/he is currently and that gets sent to the server, and in consequence to other players

    Quite simple, but since I do not have much experience with Unity/C# (yet ;)), plus I always prefer to not re-invent the wheel my question is:
    Will any networking library such as
    - NetCode for Game Objects
    - Mirror
    - Photon
    help me?

    Or should I simply go with UnityWebRequest + Socket.IO from asset store?

    Thank you in advance!
     
  2. Lukeesta

    Lukeesta

    Joined:
    Jan 7, 2016
    Posts:
    62
    Netcode for GameObjects and Mirror and Photon Fusion need you to run your server as a Unity application so if you want to run a server using angular they are not an option.

    If you just need something to handle web requests and low level messaging using websockets using just UnityWebRequest and a websocket implementation is the way to go.
     
    Sachem1000 likes this.
  3. Sachem1000

    Sachem1000

    Joined:
    Mar 17, 2023
    Posts:
    7
    Hi Lukeesta

    My server will be based on PHP + Node.js, not Angular, but I understand it was a "typo" ;)

    Thank you so much for your reply. I thought this was the case, but it's always better to ask and confirm. Thanks!