Physics works differently with networking for shooting balls

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:

public void Fire()
    {
        if (!isLocalPlayer)
        {
            return;
        }

        Vector3 direction = CalculateDirection();

        rb.AddForce(direction * thrust, ForceMode.Impulse);
    }

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:
3362481--263443--upload_2018-1-22_3-42-23.png

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.

Bump

Bump, please help me.

You might would rather think about doing this with messages instead.

Instead of syncing positions,rotations constantly, you might would rather just try sending a message saying ‘Hey this ball moved, this is where it’s moving too’

So with that being said, what would happen is, instead of having the Network calculate positions and rotations, they would be done locally.

Example

1: Player 1 hits their ball, it goes into air.
2: Player 1 sends a message to Player 2 saying hey I hit my ball, this is where it’s going, etc.
3: Player 2 gets the message and on his end makes Player 1’s ball move in the direction that Player 1 sent it too.
4: Player 1 and 2 would get identical results for the most part. (maybe not always - testing is the only way to be sure).

With that being said, instead of relying on the Network to sync things, it would be treated as if it were a single player game, thus calculating things on your end.

This would all-together remove the need to sync anything over the network aside from the messages communicating that we hit the balls. Not only will that save you tons of money, but it may just work.

Now keep in mind, I’m not saying this will absolutely without a doubt work for your situation.
But it doesn’t hurt to try.

Networking and Physics without an Authoritative server have never mixed correctly and can give undesired results.
Which is why I’m hoping what I mentioned will work for you.

It’s how I’ve always done bullets and such, never failed me yet.

1 Like

Yes I did something like

Yes, I did the similar things today and solve the problem. Both balls now have no local player authority and are owned by the host. Only the host do the physical calculation and send the movement/location of the balls to the clients. This works well.

1 Like