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

How to properly sync ball with dynamic Rigidbody2D over network so everyone has the same experience?

Discussion in 'Physics' started by novica89, Apr 17, 2019.

  1. novica89

    novica89

    Joined:
    Feb 8, 2019
    Posts:
    9
    Hi everyone!

    I am getting crazy over last few days in googling the issues mentioned in the title but to no use. Most of the answers I found were either hardly relevant or very vague. I have a simple game with 2 players (that have dynamic rigidbody2D's on them as well because I need gravity and collision to work ofc.). I also have one more object (volleyball) which is a dynamic Rigidbody2D as well since I need these two players to just bounce it over the net and score points if the ball touches the ground on either side of the net (game pretty much like Blobby Volley if you have ever played it).

    Problem is that the ball is moving perfectly fine for the player who is a Client and also a Host, but it is behaving really weird and inconsistent for the player who is a Client only and when his player game object collides with the ball. The ball on collision starts going around the actual player object and only sometimes it gets a proper impact calculation and behaves as it should, but this happens on a really small number of occasions. My guess from the research I've done online is that Physics are being calculated differently for both players for some reason and I should either:
    1. Fake everything and not use Rigidbody2D on the ball (which I guess would take a whole lot of work for such a small and simple game)
    2. Let the server only have the ball with dynamic Rigidbody2D on it and the clients will only have the ball with kinematic Rigidbody2D (this sounds like something that requires less code and fiddling around than the first option, but I am completely unable to find any good source of info on how to do this). Then, the server would in a way use ClientRPC to tell both clients the balls location and rotation as it moves etc.
    3. Your solution goes here (hopefully)

    Thank you very much for trying to help!