- Home /
How to sync a ball, where two players kick it in turns? (Multiplayer game using UNET)
I have been trying to understand how to synchronise a rigidbody (ball) between a client and server.
When the player on the host kicks the ball - the ball moving is visible for both client and host When the player on the client side kicks the ball - the ball doesn't move but stays in one place (as it automatically returns back to its start position even if I try to move it on the scene when I am a player on a client)
The ball gameobject has NetworkIdentity and Network Transform - Rigidbody 3D attached to it.
When the player kicks the ball, the method invoked is within the player's control script and it does:
[Command] void CmdShoot(GameObject ball){ ball.GetComponent().AddForce (ball.transform.forward * pushForce); }
, however the ball doesn't want to move when a player on a client kicks the ball.
Can anyone suggest any ideas with that?
I've had this problem in the past. It seemed the problem for me was that the "ball" object I was referencing wasn't working when run as a Command. I had to explicitly identify it using GameObject.Find which is bad practice, but for what I was doing wasn't a problem.
The thing with the ball is that even if I try to move it (transform its location) from the Unity scene window with my mouse, when I'm playing from the client side, the ball immediately returns back to it original position. Is it something to do with the authority that the client doesn't have over the ball I believe but the Command word by itself on top of the method doesnt seem to solve the issue. I tried identifying it with Gameobject.Find but that doesnt seem to be the case with me.
$$anonymous$$aybe add the Network Transform Visualizer to get an idea of whats going on.
Just to make sure, you haven't enabled any form of isLocalPlayer?