0

I was initially going to write what looked like a four paragraph essay to explain what I'm working on, but it wasn't nessecary. In summary, I'm a rookie at Unity and know very little about how to create a platform in which I can store(send and retrieve from other clients) data in "the cloud". Yet, I need to be able to do so for my project.

using System.Collections.Generic;
using UnityEngine;

public class MultiplayerMoveMe : MonoBehaviour
{

    //Note: I am making a retro-style game where all sprites face the camera, so the rotation of the players is not a factor that needs considering here; just the position.
    //I have a fleshed-out idea on how I will do all of this, however I am completely foreign in all things server-related on this scale so I need some assistance(not the most prideful circumstances).
    public GameObject p2Obj;

    void Start()
    {
        //Anything that I might need to add that the serverGet() function might require
    }

    void serverGet(int playerNum, string reqType)
    {
        //On their side, every frame, the second player's X, Y, and Z pos should be packed into a string with seperator char '|' and then filed on the server under playerdata/2/pos/
        //Then, this script(on the side of player 1) would(every frame, displaced by +1 frame initially) take the player number and the reqType to find said directory online with THIS function to return the value.
        //Funny thing is; I have no idea what I'm doing.


        //And no, I haven't connected to a server yet. I also want to stay away from any third party apps for this since this is small-scale and I only wish to learn the ins and outs of all of this.


    }

    void Update()
    {
        String p2Position = serverGet(2,"pos");
        // String p2Position's value is currently "x|y|z"
        String[] sl = p2Position.Split('|');
        float xPos = float.parse(sl[0]);
        float yPos = float.parse(sl[1]);
        float zPos = float.parse(sl[2]);
        // Now that all values are floats, we can feed them into the thingamabobber to change the position of the other player from our side.
        p2Obj.transform.position = new Vector3(xPos, yPos, zPos);
    }
}

Below I have a script which, if the serverGet() function's contents were actually existant(and functional, of course), would set the position of the second player to their position according to the data online, which the instance from their side submits in the first place(every frame as well, -1 frame initial displacement so that everything works). This way, if I move on one computer as "player 2", the computer in which I am playing as "player 1" will show the movement of player 2 as it progresses every frame. In other words, basically all calculation is client-side, but the actual communication is(unavoidably) server-side. That server-side is what I'm clueless about, and would appreciate if anyone here could lead me a step in the right direction.

As for the script that actually submits the terms to the server, that will come with my understanding of all of this; which again, I don't have as of right now.

John Wick
  • 1
  • 1
  • Is there are reason why you would not use the native unity network tech? https://docs.unity3d.com/Manual/UNet.html – sommmen May 10 '21 at 14:41
  • Wasn't that deprecated? – John Wick May 10 '21 at 14:44
  • yes, that one is deprecated – Fattie May 10 '21 at 16:29
  • Perhaps its deprecated, but my question was more in the lines of 'why are you trying to reinvent the wheel when there are already solutions out there' - was there a specific use-case or something? The answer from fattie seems to put that in better light. – sommmen May 10 '21 at 18:13

1 Answers1

1

There seems to have been a number of questions lately: "So I'm gonna write a MP game engine from scratch!" (Example.)

Do try to understand the scale of your problem. You're about to embark on a PhD level enterprise that will take months of full-time work at the minimum. It would be insanity to not, first, spend a few days with current systems to gain some basic principles.

  • Similarly, Photon is very popular for mmp systems, https://www.raywenderlich.com/1142814-introduction-to-multiplayer-games-with-unity-and-photon next spend a few days making toy Photon/Unity systems to learn more.

  • Finally Mirror networking is the one that is "like Unity's old networking" https://assetstore.unity.com/packages/tools/network/mirror-129321 so really you should try that a little too.

  • Finally on the face of it to literally answer your question as is, click over to AWS, spin up some ubuntu EC2 instances, and start work on a "simple" game server, so almost certainly you'd use Node/Express/SQL and likely websockets (just to get started, you'd have to move to raw udp communications eventually). It's just not realistic to start doing that though until you familiarize yourself with some basic existing systems.

halfer
  • 19,824
  • 17
  • 99
  • 186
Fattie
  • 27,874
  • 70
  • 431
  • 719