Photon server best practice unity implementation

Options
Hello all,

Im using photon server to have a presistent world for an MMORPG, I dont have too much, just starting.
I can connect to the server from a gameobject creating a new thread and calling the peer.Service in an infinite loop.
So this object send an opcustom every time I press a key and send request to move the position of the object in the server and then gets this position in the response and update the position using properties and then setting the transform.position in the client because I cannor access directly to the gameobject from another thread.
Is this the best way to handle it?

Im also storing the x and y in a json file and loading this data if disconnect and connect again. Im going to store it in a db or something else, what do you recommend?

Well, thats working great for one player, now I want to connect with another player but how I need to handle this? I wanted to create / instantiate other players but again, I cant access the main thread.

What do you recommend to handle this scenario?
What is the best way to keep every player updated with the position of the others?

Thanks a bunch!

Comments

  • chvetsov
    Options
    Hi, @Mondix

    Usually, on client you have one main thread that calls method 'Tick' or 'Quant' 30 times per second. Inside that method you call Tick method for all game objects and graphics. inside Tick method for object you do all the calculations

    For one client you have only one connection to server. In order to send/receive data you call peer.Service method once peer root method Tick call

    best,
    ilya
  • Mondix
    Options
    I tried setting the peer.Service in the update loop but the client hang out.

    Do you have an example of your recommendation?

    Thanks!
  • Mondix
    Options
    Also Im understanding the mmo demo and getting some ideas from there, but I wanted to truly understand the implementation.

    Thanks again!
  • chvetsov
    Options
    We do not support MMO demo anymore
    It is overcomplicated and difficult for both understanding and supporting

    That is true that some ideas can be taken from there. One of them is traffic control based on object location

    best,
    ilya
  • Mondix
    Options
    So what should I do to start a new unity empty project and connect multiple players using photon server?

    There is a lot of docs but nothing related to unity-photon implementation itself :(

    Will continue trying my best of course, but if there is some small project that would be great!

  • chvetsov
    Options
    we have basically two products for you
    1. PUN - you have a lot of docs and samples for it
    2. .Net client sdk - it is used by PUN and you may use it in your way. Samples of how to use it you may find on our site. All you need is add it correctly to Unity.

    my colleague @JohnTube can give you a more precise answer about docs

    best,
    ilya
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Mondix,

    Thank you for choosing Photon!

    As my colleague @Ilya already suggested, I think the best thing to do now since you're starting with Photon is to use PUN2 and follow the "PUN Basics Tutorial".
    If you want to connect to the self-hosted Photon server you just need to configure this in PhotonServerSettings (Address and Port in AppSettings).