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

Third Party How Can I Improve My Game`s Sync Speed? (Unity & Mirror)

Discussion in 'Multiplayer' started by Dans97, Mar 7, 2022.

  1. Dans97

    Dans97

    Joined:
    Nov 19, 2019
    Posts:
    5
    Hi, guys. I need help with something here.

    I`m making a foot volley game in Unity, using Mirror. Two teams, two athletes in each team. I`m using a dedicated server, so everything like movement and input needs to be validated by the server first. I may be wrong here, but I`ve made it so that only the server can move the ball. Its position is then broadcasted.

    I`m using Tennis Clash as a reference. My game is very similar. When the ball gets near enough the athlete, I slow it down while waiting for an input. If no input comes through, the ball keeps going. Otherwise, the ball is returned based on user input. My problem is: it`s taking too long. When the ball is finally moved, it already touched the floor (too late).

    How can I improve this? I have to process the player input so I can add a direction and a force to the ball, much like Tennis Clash. But in Tennis Clash the update is instantaneous, as far as I can tell. The ball immediately changes direction. In my game the ball almost always hits the floor and only then it moves. I was using isKinematic at first. I stopped the ball, waited for input, then moved the ball. It worked, but stopping the ball made the game too slow. I need fast changes.

    Any ideas?
     
    Last edited: Mar 7, 2022
  2. e_Zinc

    e_Zinc

    Joined:
    Oct 31, 2019
    Posts:
    18
    • Server owns the ball's movement/velocity and sends these as updates to all clients
    • However when a client hits a ball, it should instantly set its position/velocity to what is desired so that it feels instant for the player. It then sends this position/velocity to the server.
    • The server validates whether or not this was a legal hit. If the player was way too far from the ball or the position/velocity is ridiculous, the server can reject it. If it's approved, the server sets this position/velocity update and sends to all clients.
    • The client that hit the ball will eventually receive position/velocity data along with all other clients as a result of its position/velocity message earlier. The ball will interpolate slightly to adjust from its clientside position/velocity values.
    More tweaking can be done after this. For example, sending a timestamp along with the position/velocity to better interpolate the ball's state.

    Thankfully, games that have a ball involved have more leeway with its community than shooter/fighting games. Rocket League is a good example of a physics-based ball that is obviously using this technique, because you can see the ball interpolate wildly and the game has cheats that allow you to hit the ball in set directions/velocities.
     
    Dans97 likes this.