Search Unity

Physics works differently with networking for shooting balls

Discussion in 'Physics' started by WisherHK, Jan 24, 2018.

  1. WisherHK


    Jan 3, 2018
    Hello guys.

    I made a single player game, which is similar to a golf game but the players can shoot each others. What I want to do now is to change it into a networking game, so i firstly test the game by changing it into a LAN game.

    Basic information of the player object:
    The player object(ball) is created with a capsule collider which mass = 1 and drag = 1. It is shoot by using AddForce() and I set the force of each shoot to be identical for testing. The force mode I chose is ForceMode.Impulse in order to look like hitting a golf ball. I freeze the rotation of the all axis since the ball is actually in cylinder shape and I don't want to be rolling after being hit.

    What is expected to happen by me:
    For testing, I put the ball of host on (0,0,-1) and the ball of client on (0, 0, 1),then shoot one of them to the direction of the other ball.
    Since the ball of the host and client are in the same mass and drag, after they are contacted, they should stick and move together. This works when the game is still single player.
    The function for shooting the player:
    Code (CSharp):
    1. public void Fire()
    2.     {
    3.         if (!isLocalPlayer)
    4.         {
    5.             return;
    6.         }
    7.         Vector3 direction = CalculateDirection();
    8.         rb.AddForce(direction * thrust, ForceMode.Impulse);
    9.     }
    What happened after adding networking functionality (by adding NetworkManager, NetworkTransform, etc.):
    However, for the first shoot of the host, the balls collide and both of them bounce to the opposite direction with a very high velocity. After that, if I shoot the ball of the host again, when the balls collide, the ball of host bounces back with lower speed compared to the first shoot, but the balls of the client barely move as if it is a very heavy object.
    If I shoot the ball of the client, the same situation happened, the ball of client bounces back while the ball of host barely move, but shooting the ball of client does not has the first-shoot problem (which both of the balls bounce back with a very high velocity).
    Here is the setting of NetworkTransform of the player object:

    I have done a lot of research on the Internet and the documentation today, but still cannot find the suitable solution. This might be an easy question for an experienced programmer but I struggled a lot with this problem. Please help me.
  2. utimago


    Feb 28, 2017
    Were you able to since this? I have a similar problem.