Search Unity

Advice on which Multiplayer direction to start with

Discussion in 'Multiplayer' started by matthewbrand, Jun 8, 2017.

  1. matthewbrand

    matthewbrand

    Joined:
    Jan 9, 2017
    Posts:
    25
    Hey all! I'm building a turn-based online multiplayer game with 2 players that each have a team of 3 tanks. For each turn, the player can choose one of their tanks, move a certain distance and shoot projectiles.

    I've been researching and playing around with UNET and also with the traditional Unity lobby system. Neither one feels right because of the way that player spawning works. Rather than have the objects use NetworkIdenties to show the player positions automatically, I'm thinking about using network messaging to display the turns either by:
    1. sending a message each frame with the position of the current tank that's moving
    2. with a stored queue of positions that gets sent when the current player finishes their move that gets run on all other clients

    Do these methods sound feasible and reasonable?

    Does anyone have recommendations on whether to go with UNET, traditional Unity networking, or something else, like Photon?
     
  2. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    UNET will work well for either of those methods (though I have a suggestion) because your game is turn-based. The only time things have to be tightly in-sync is at the end/beginning of a turn.
    For method 2, spawn a generic player that can issue all your commands, spawn objects like your tanks, and apply updates to them. The NetworkManager can spawn it for you. The current player would send the positions at the end of their turn, send it to the server and/or other player, and you would lerp over time between that position and the last to show the movement to the other player. No need to send many position updates, unless you require a certain path be followed. In that case, you'd probably only send the set of points that make up the path.
    For method 1, and I'm assuming this is because you want both players to see the movement at roughly the same time, you might as well spawn the tanks as players. Just like in method 2, spawn a generic (invisible) player in NetworkManager, but once your player is started, you can spawn tanks with client authority (will let you move them, but the other guy can't) or simply spawn them and use AddPlayerForConnection to make them player objects also.
     
  3. matthewbrand

    matthewbrand

    Joined:
    Jan 9, 2017
    Posts:
    25
    OH! I hadn't thought about having the player object with the NetworkIdentity be an empty GameObject, that's really smart. That way nothing actually gets spawned on the screen, and everything created can be controlled by local authority. Thanks so much that is really helpful! I had been trying to use the tank as the spawning object, and it just wasn't working the way I wanted.
     
  4. matthewbrand

    matthewbrand

    Joined:
    Jan 9, 2017
    Posts:
    25