Search Unity

Third Party Photon PUN Question: How to send input to server instead of it's new position?

Discussion in 'Multiplayer' started by UnbreakableOne, Nov 8, 2015.

  1. UnbreakableOne

    UnbreakableOne

    Joined:
    Nov 16, 2013
    Posts:
    168
    Hi,

    How can I send all input to the server, which will convert your data to actual movement and send back your new position to everyone on the network. The advantage is that everything is synchronized on the server with PUN?

    Thanks
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    In some script, wou need to keep track of any input you want to sync.

    Instantiate a GameObject per player. For that, create a prefab with a PhotonView and a script that implements OnPhotonSerializeView(). Said script must be dragged into the PhotonView's "observed" field.
    Inside OnPhotonSerializeView(), you can write your own input into a stream to send. For remote players, read the input they sent.
    This does not involve any logic on the server but it gets the idea across, I hope.

    If you want to implement movement on the server, I would do it slightly differently. You should then use PhotonNetwork.RaiseEvent, to send your input regularly. You can read this on the server-side, when you got the Photon Server SDK and modify the Operation RaiseEvent (handles the calls from the clients)...
     
  3. purpl3grape

    purpl3grape

    Joined:
    Oct 18, 2015
    Posts:
    8
    For driving game, would sending every change in value for an analog input be costly? Or am I overthinking this?
    Because if the input value changes a lot, there would be a lot of events being sent, and that's just for a steering wheel controller, and if there are other analog inputs as well, there may be too many events for 2 or more other players.