- Home /
Vehicles owned by Server being controlled by other NetworkPlayers in a network game
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
Answer by Muuskii · Jul 26, 2012 at 03:52 PM
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.
Your answer
Follow this Question
Related Questions
Looking for a good starting point for area instancing in an MMO setting 0 Answers
Help| Sync' boolean variable (Friendly Fire) 0 Answers
Networking Sync SetActive Not Working 0 Answers
Unity networking tutorial? 6 Answers
Animating online users sprite 0 Answers