Hi guys,
I'm building a networked tank battle game. The server instantiates several vehicles when the scene loads, and players have the option to control either the driving functionality or the shooting functionality.
Playing as the server, any actions made are observed by clients. Playing as a client, any actions made are ignored by the server, and none but the client in question can observe the change in translation or rotation.
What's the best way to have two players control different transforms in the same gameObject, regardless of who owns the gameObject?
Thanks,
Chris
I assume you’re using NetworkViews to synchronize the transform data of your tanks, preferably using a NetworkRigidbody script as the observed value.
You mentioned that the Server Instantiates the Tanks, meaning that the server owns them and all clients will look for the server to tell them where the tank is.
This is done in the OnSerializeNetworkView function of the NetworkRigid body script I mentioned. In that function the “owner” of an object will have
if (stream.isWriting)
evaluate to true and will write it’s data for everyone else to read.
What this is all coming down to is that if the server owns everything; the clients never get to write anything, and therefore are practically watching a movie. You need to either instantiate the tanks on the client whenever he needs one (This allows cheating easily) Or you have some sort of “controller” object that is instantiated by the client when connected to server that has a network view observing the clients keyboard and mouse Input. When the server reads the information out of the controller object it then moves the currently controlled tank based off that Input.
That’s at least how I setup my first Networking game, other methods may vary.