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

Resolved Player movement question.

Discussion in 'Multiplayer' started by VentaGames, Aug 26, 2023.

  1. VentaGames

    VentaGames

    Joined:
    Jul 9, 2021
    Posts:
    122
    Hi there, I'm new to Multiplier, so please help me to understand the following.

    My multiplayer mode is 1 vs 1 challenge, only two players max.
    I'm using Lobby to Relay.
    On the host device, I can move my local player,
    But I can't move the player on the client device as it ignores transform. position/rotation.
    Both player's objects have Network Object and Network Transform.
    Now,
    The only thing I can do is to send control commands to the host, update the position there, and then it updates on the client device.
    But is this fair? One player controls its player locally, the second over the network with all these latency, ping, etc...
    Or did i miss something?
     
  2. Simplisticated_Development

    Simplisticated_Development

    Joined:
    Jun 26, 2023
    Posts:
    61

    I have the same issue. It might have to do with a NetworkTransform component if you use mirror...
     
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    You just understood why competitive games prefer or only implement a server/client architecture, rather than host-client/client. ;)

    The host-client is always at an advantage - host/client mode is not suitable for competitive action games.

    There is NOTHING you can do about this except using a server-client architecture. This at least ensures each client has some latency to the server, and the advantage is with the one who has a faster connection to the Internet and the server.
     
  4. VentaGames

    VentaGames

    Joined:
    Jul 9, 2021
    Posts:
    122
    Actually, I've managed to solve this.
    My game is a mobile one, and it allows two players to challenge each other.
    I just inherited from the NetworkTransform class and then overloaded OnIsServerAuthoritative method.
    And now both devices can control their own players.
     
  5. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,326
    Yes, use NetworkTransform and set SyncDirection to ClientToServer for client authoritative movement!
     
  6. VentaGames

    VentaGames

    Joined:
    Jul 9, 2021
    Posts:
    122
    SyncDirection is from UNet which is deprecated.
     
  7. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,326
    I added SyncDirection to Mirror a few months ago, that's not from UNET.
    You can try our Tanks example and check the player prefab:
    2023-08-27 - 16-50-29@2x.png