Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved Multiplayer Card Game with NGO

Discussion in 'Netcode for GameObjects' started by Ghigolus, Dec 20, 2022.

  1. Ghigolus


    Jan 15, 2022
    Hello, I am trying to make a 2-players online card game with NGO but my problem is that I have one player in front of the other and I need to know if there is a way to spawn a card in his default position for the current player and spawn it mirrored for the other player. Maybe it is more simple than I know but I have no idea on how to implement this function.

    Thanks in advance for any repliy
  2. CodeSmile


    Apr 10, 2014
    I'm just going to point out what I say to everyone trying to implement a card game or any kind of GUI driven game like this where synchronization of the cards or GUI is not important, and not actually needed: try to keep your synchronized data entirely data-driven, rather than making the cards or the GUI elements network objects.

    It boils down to the fact that in the case of a card game, you are essentially just dealing with say 32 variables (cards), with each player "holding" maybe four of these, and the tables "holds" another couple of these. So all you really need is to synchronize the data that tells you how the cards are distributed across players, table, decks, hands, and so on. None of it is a NetworkObject, just NetworkVariables or a few serialized structs.

    Say the player wants to play a card from his hand to the table. You would send a Rpc command to the server, telling the server which card the client wants to play. Server checks that this is allowed, and replies with an RPC to tell the player the changed state of cards, meaning: card from his hand is removed and added to the table stack. Now the client simply plays a completely local animation of playing that card, and all other clients do the same thing, but whether the card moves at the same time, the same speed, or even the precise same location on the table for every client simply doesn't matter.

    Therefore, those cards should not be network objects. You can then force each client's cards to draw on top, to draw mirrored, to draw semi-transparent for a ghost player or whatever - this is for each client to decide locally and you're in full control of it. ;)
    Faquicho, RikuTheFuffs-U and Ghigolus like this.