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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to have a function that the host triggers lock the client out from calling it too

Discussion in 'Netcode for GameObjects' started by Skngh, Mar 5, 2023.

  1. Skngh

    Skngh

    Joined:
    Jul 3, 2020
    Posts:
    6
    I'm making a competitive 1v1 game where two players are essentially fighting to get to a star. It is common for both players to be right at the star when it is acquired, so I keep having the issue that one of them will get it first, but before it updates for the other, they also get it and then the game awards both of them the point. I'm not sure if it would be as simple as a boolean to lock the other out of it, since it gets confusing with serverRPC's and such, so I was wondering what to do.

    Thanks!
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,191
    The best practice solution for competitive games is to let the server decide. In a 1v1 where one plays as the host, that player will always have a significant advantage in online play since that player will not experience any round-trip lag at all.

    If you do it client authoritative you'd still have to inform the server who picked it up at what tick and even then they may both pick it up in the same tick.
     
    RikuTheFuffs likes this.
  3. Skngh

    Skngh

    Joined:
    Jul 3, 2020
    Posts:
    6
    How do I check what tick they pick it up at? I plan to let the server decide but I'm just not totally sure how to logically figure out who got it first