Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question "Multiplayer" but the players shouldn't meet in the same scene

Discussion in 'Multiplayer' started by EllaDott, Jul 22, 2022.

  1. EllaDott

    EllaDott

    Joined:
    May 4, 2017
    Posts:
    13
    Hi, I'm working on my first multiplayer game, and I'm feeling a bit overwhelmed. I picked the classic pen and paper Battleship game thinking this might be a good start since it's essentially turn based. What I considered an advantage/easier to implement looks to be the opposite. Each player has a different set of "facts" they are seeing, so they're not looking at the same exact scene. Because of that I wanted to go as far as to put each player into a different instance / copy of the same scene. I've been checking out some multiplayer examples but I'm a bit confuzzled - in most games the players are coexisting in the same scene and that's how they get "linked up". Perhaps I'm not using the right terminology or not googling the right thing - or perhaps I'm misunderstanding how all of this works - if you can point me in the right direction that would be great.

    Essentially what I'm hoping for is this:
    • both players are spawned in a local scene of their choice (I have various themes etc, both players can choose the same theme if they like). They don't see each other, they don't interact directly, the players are not connected "directly" - for instance a player placing their own ship on a particular tile doesn't in any way manifest that ship in the opponent's scene.
    • each scene has a game manager. These game managers are being given instructions by the server and this is what connects the players / clients.
    • player1 makes a hit choice -> Game manager disables player1s actions -> Game manager communicates hit choice to server -> Server communicates this hit choice to game manager of player2 which then checks player2's ship placement, plays desired effect and sends back success/fail to the server -> Server communicates success/fail to player1s game manager, which then triggers corresponding effect for player1.
    • player2s hit actions are enabled. player2 makes a hit choice... and so on
    Since the players never meet in the same scene, I'm not sure how to actually connect them - any hint at an approach or any suggested reading on this topic would be appreciated. Sorry if this is a n00b question.

    I've considered placing both players in the same scene, just in separate rooms really far away. I suppose this could work, but it feels like a hack. I'd also have to rethink how the themes would work as I've created them as separate scenes.
     
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    For the players not 'meeting' part you can simply just instantiate a player scene object for the local client and not for remote players. It's quite common to have the visible model for the networked player prefab as a separate gameobject anyway.

    So all the players would have networked player objects, and can therefore communicate howsoever you want, they just won't be able to see each other. If you're making a battleships type of game, you may not even need a visible avatar for the local player.

    For the placing tiles part of the puzzle, just don't make placing tiles a networked function, so it will only happen locally. When a player receives a hit choice, he can just compare the position sent with his set of tiles and then send back the result.

    All of this is easily achieved with any of the popular networking solutions available, but something that supports server authority like Fusion or Mirror will be better for cheat prevention.

    Unfortunately it's too big a topic for me to give actual code examples, but I hope the above helps a little.
     
    Last edited: Jul 22, 2022
  3. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    389
    AFAIK Fish-Networking is the only option, paid and free, that supports scene stacking. FishNet is free on the asset store, documentation is here https://fish-networking.gitbook.io/docs/

    You can also add an "Owner Only" observer condition in FishNet and skip the scene stacking all together. It's all covered in the documentation. If you need further help there's a discord link in there as well.