Search Unity

Not same position on every clients

Discussion in 'Multiplayer' started by Zeldarck, Aug 13, 2017.

  1. Zeldarck

    Zeldarck

    Joined:
    Feb 8, 2017
    Posts:
    10
    Hi,

    I try to learn networking in Unity, I want to make my pong game multiplayer: https://github.com/Zeldarck/Pong

    I have follow this tutorial to get the basis of networking : https://unity3d.com/fr/learn/tutori...ion-simple-multiplayer-example?playlist=29690

    In my pong, I want a player see hiself on the bottom of the screen.
    So If I have well understand we have that :
    Device 1 : got server and client 1
    Device 2 :got client 2

    On client 1 and server, we got client 2's player position at the top and client 1's player position at bottom.
    But on client 2 I want client 2's player position at bottom and client 1's player position at top.

    I tried to modify a little the tutorial exemple and change the position in the PlayerController, but I see a fantomatic player at the two place.


    Code (csharp):
    1.  
    2.         if (!isLocalPlayer)
    3.         {
    4.             if (!isServer)
    5.             {
    6.                Vector3 pos = transform.position;
    7.                 pos.x *= -1;
    8.                 pos.y *= -1;
    9.                 transform.position = pos;
    10.             }
    11.  
    12.             return;
    13.         }
    14.  
    I will continue to search alone and test further things, but I you have good advice or better approach I am open to.
    For exemple I don't know if command enter by player have to be send to server wich make movement and send back position of ball/objects/players. Or if like in the tutorial, players make move, send them to the server wich send it to other players. For me the first it's better, but with local interpolation to not wait the server update. But I really don't know enough and where search first on unity networking to achieve it :)


    thank you

    Zel'
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I haven't looked at your project, so don't know if it is 2D, 3D, etc, but the first way I would attack this would be rather than trying to swap in game positions of the 2nd player I would see if I can just flip the 2nd player's camera upside down.
     
  3. Zeldarck

    Zeldarck

    Joined:
    Feb 8, 2017
    Posts:
    10
    OH thank you !
    I didn't think at that trick, I don't enough think of the view is determine by camera :)