Search Unity

Resolved how to AI player take the role of disconnected player?

Discussion in 'Netcode for GameObjects' started by sava-game, Mar 20, 2023.

  1. sava-game

    sava-game

    Joined:
    Feb 14, 2023
    Posts:
    21
    Hello, I am going to let AI player take the of disconnected player. so other human player continue to play the game against AI in PvP. but all game objects disappear when the host player leaves the game. Since the host player is responsible for managing the server and hosting game session, if they leave the game, the server shout down and all gameobjects on the server maybe destroyed. How can I keep all gameobjects when the host player leaves the game? Please help me.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
    If the host leaves, the game ends. Nothing you can do about it as there is no host migration in NGO yet. The only solution would be to run an actual (dedicated) server instance so you have only clients playing.
     
  3. sava-game

    sava-game

    Joined:
    Feb 14, 2023
    Posts:
    21
    Thanks for your clear answer.
    It took me a week to find this answer.
    Then, I am going to use Multiplay(DGS), Matchmaker service to implement the following senario.
    Is it possible with those service?
    I am waiting for your confirmation
    --------------- Game Play Logic ---------------------------
    I am trying to implement 1vs1 using UGS
    • Users select the desired battle arena.
    • Wait for the online opponent to enter.
    -When an online opponent comes in, a 1vs1 begins. the logic I am saying is similar to this game. https://play.google.com/store/apps/details?id=com.uken.pool&hl=en_US&gl=US -Player 1 selects the desired battle arena. -Transition to the matchmaking scene.
    • Player1 first searches for the lobby he wants.
    (The lobby filter is determined by the selected battle arena.)
    • If there is no desired lobby, create and join the lobby.
    • And wait for another player (player2) to come in.
    • Player2 also selects the battle arena he wants, just like player1.
    • transition to matchmaking scene
    • Player2 searches for the lobby he wants.
    • If the lobby created by player1 is correct (i.e. if you select the same battle arena as player1), join that lobby.
    • The game starts.
    -If there is no desired lobby, just like player1, create and join the lobby and wait for the opponent player. The important thing here is that if any player leaves during the 1vs1, the game does not end, but the AI works and allows the opposing player to continue the game. The problem is that if the hosting player leaves, the game ends and the scene changes. I want the other player to continue playing with the AI player even if one of the two players exits.

    ----------------------------------------------------------------------------------------------------------------------------------------------

    Looking forward to hearing from you.
    Best
    Sava
     
  4. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    I think it is possible with Multiplay ans Matchmaker. Both players will be clients and the server machine will control the AI in case one of them leaves.
     
  5. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
  6. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hey Sava, yes, it's possible. Your workflow also includes the usage of the Lobby service in it (which Matchmaker dosn't use as they're an alternative way of making players find each other).

    So you'll need to use matchmaker + dedicated servers, with lobbies as a fallback if you want a player to able to join mid-session.
     
  7. sava-game

    sava-game

    Joined:
    Feb 14, 2023
    Posts:
    21
    Thank you for your help.